Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios adjustsFontSizeToFitWidth不显示带有可视自动布局的完整标签_Ios_Objective C_Autolayout_Uilabel_Visual Format Language - Fatal编程技术网

Ios adjustsFontSizeToFitWidth不显示带有可视自动布局的完整标签

Ios adjustsFontSizeToFitWidth不显示带有可视自动布局的完整标签,ios,objective-c,autolayout,uilabel,visual-format-language,Ios,Objective C,Autolayout,Uilabel,Visual Format Language,我正试图用auto layout制作一个带有两个标签、一个进度条和一个要取消的X的小通知框。我用字体缩放设置了相同的标签,但看起来有些标签被剪掉了。我不确定这是我的自动布局代码还是UILabel代码造成的 您可以看到文本根本没有对齐,播放标签完全被切断 相关代码: // Container pttProgressContainer = [UIView new]; [pttProgressContainer setBackgroundColor:UIColorFromRG

我正试图用auto layout制作一个带有两个标签、一个进度条和一个要取消的X的小通知框。我用字体缩放设置了相同的标签,但看起来有些标签被剪掉了。我不确定这是我的自动布局代码还是UILabel代码造成的

您可以看到文本根本没有对齐,播放标签完全被切断

相关代码:

    // Container
    pttProgressContainer = [UIView new];
    [pttProgressContainer setBackgroundColor:UIColorFromRGBWithAlpha(0x3a4362, 0.10)];
    [pttProgressContainer setTranslatesAutoresizingMaskIntoConstraints:NO];
    [pttContainer addSubview:pttProgressContainer];

    // Separator
    UIView *progressContainer1pxView = [UIView new];
    [progressContainer1pxView setBackgroundColor:[UIColor whiteColor]];
    [progressContainer1pxView setTranslatesAutoresizingMaskIntoConstraints:NO];
    [pttProgressContainer addSubview:progressContainer1pxView];

    // Progress viewzlers
    UIView *progressViewLeft = [UIView new];
    [progressViewLeft setTranslatesAutoresizingMaskIntoConstraints:NO];
    [pttProgressContainer addSubview:progressViewLeft];
    UIView *progressViewRight = [UIView new];
    [progressViewRight setTranslatesAutoresizingMaskIntoConstraints:NO];
    [pttProgressContainer addSubview:progressViewRight];

    // Progress view
    pttProgressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
    [pttProgressView setTranslatesAutoresizingMaskIntoConstraints:NO];
    [pttProgressView setProgress:0.5 animated:NO];
    [pttProgressView setTrackTintColor:[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.20]];
    [pttProgressView setProgressTintColor:UIColorFromRGB(0xd7d7d7)];
    [[pttProgressView layer] setCornerRadius:5];
    [[pttProgressView layer] setMasksToBounds:YES];
    [pttProgressView setClipsToBounds:YES];
    [progressViewLeft addSubview:pttProgressView];

    // Now the playing in label countdown
    UILabel *pttPlayingInLabel = [UILabel new];
    [pttPlayingInLabel setFont:[UIFont systemFontOfSize:20]];
    [pttPlayingInLabel setAdjustsFontSizeToFitWidth:YES];
    [pttPlayingInLabel setMinimumScaleFactor:8/20];
    [pttPlayingInLabel setTextAlignment:NSTextAlignmentLeft];
    [pttPlayingInLabel setTextColor:[UIColor whiteColor]];
    [pttPlayingInLabel setContentMode:UIViewContentModeCenter];
    [pttPlayingInLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
    [pttPlayingInLabel setText:@"Playing In..."];
    [progressViewLeft addSubview:pttPlayingInLabel];

    // Countdown numbers
    pttPlayingCountdownLabel = [UILabel new];
    [pttPlayingCountdownLabel setFont:[UIFont systemFontOfSize:20]];
    [pttPlayingCountdownLabel setMinimumScaleFactor:8/20];
    [pttPlayingCountdownLabel setAdjustsFontSizeToFitWidth:YES];
    [pttPlayingCountdownLabel setTextAlignment:NSTextAlignmentRight];
    [pttPlayingCountdownLabel setContentMode:UIViewContentModeCenter];
    [pttPlayingCountdownLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
    [pttPlayingCountdownLabel setTextColor:[UIColor whiteColor]];
    [pttPlayingCountdownLabel setText:@"5"];
    [progressViewLeft addSubview:pttPlayingCountdownLabel];

    // The button del cancel
    pttCancelPlayingButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [pttCancelPlayingButton setTranslatesAutoresizingMaskIntoConstraints:NO];
    [pttCancelPlayingButton setBackgroundImage:[UIImage imageNamed:@"ptt-button-delay-cancel.png"] forState:UIControlStateNormal];
//    [pttCancelPlayingButton setBackgroundColor:[UIColor brownColor]];
//    [pttCancelPlayingButton setTitle:@"C" forState:UIControlStateNormal];
    [progressViewRight addSubview:pttCancelPlayingButton];

    // Progress danker
    [pttProgressContainer addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[progressContainer1pxView(==1)]-[progressViewLeft]-|"
                                                                         options:0
                                                                         metrics:metrics
                                                                           views:views]];
    /*
    [pttProgressContainer addConstraint:[NSLayoutConstraint constraintWithItem:progressViewRight
                                                                     attribute:NSLayoutAttributeCenterY
                                                                     relatedBy:NSLayoutRelationEqual
                                                                        toItem:progressViewLeft
                                                                     attribute:NSLayoutAttributeCenterY
                                                                    multiplier:1.0
                                                                      constant:0]];
    [pttProgressContainer addConstraint:[NSLayoutConstraint constraintWithItem:progressViewRight
                                                                     attribute:NSLayoutAttributeHeight
                                                                     relatedBy:NSLayoutRelationEqual
                                                                        toItem:progressViewLeft
                                                                     attribute:NSLayoutAttributeHeight
                                                                    multiplier:1.0
                                                                      constant:0]];
     */

    // Visual horizontal
    [pttProgressContainer addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|[progressContainer1pxView]|"
                                                                                 options:NSLayoutFormatAlignAllTop | NSLayoutFormatAlignAllBottom
                                                                                 metrics:metrics
                                                                                   views:views]];
    [pttProgressContainer addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|-[progressViewLeft]-[progressViewRight(==40)]-|"
                                                                         options:NSLayoutFormatAlignAllBottom | NSLayoutFormatAlignAllTop
                                                                         metrics:metrics
                                                                           views:views]];

    // Inner danker
    [progressViewLeft addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[pttPlayingInLabel]-[pttProgressView(==3)]-|"
                                                                                 options:NSLayoutFormatAlignAllLeading
                                                                                 metrics:metrics
                                                                                   views:views]];
    /*
    [progressViewLeft addConstraint:[NSLayoutConstraint constraintWithItem:pttPlayingCountdownLabel
                                                                     attribute:NSLayoutAttributeCenterY
                                                                     relatedBy:NSLayoutRelationEqual
                                                                        toItem:pttPlayingInLabel
                                                                     attribute:NSLayoutAttributeCenterY
                                                                    multiplier:1.0
                                                                      constant:0]];
    [progressViewLeft addConstraint:[NSLayoutConstraint constraintWithItem:pttPlayingCountdownLabel
                                                                     attribute:NSLayoutAttributeHeight
                                                                     relatedBy:NSLayoutRelationEqual
                                                                        toItem:pttPlayingInLabel
                                                                     attribute:NSLayoutAttributeHeight
                                                                    multiplier:1.0
                                                                      constant:0]];
     */


    // Visual horizontal
    [progressViewLeft addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|-[pttPlayingInLabel]-[pttPlayingCountdownLabel(==20)]-|"
                                                                                 options:NSLayoutFormatAlignAllBaseline
                                                                                 metrics:metrics
                                                                                   views:views]];
    [progressViewLeft addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|-[pttProgressView]-|"
                                                                                 options:0
                                                                                 metrics:metrics
                                                                                   views:views]];

    // Now for the inner danker right
    [progressViewRight addConstraint:[NSLayoutConstraint constraintWithItem:pttCancelPlayingButton
                                                                      attribute:NSLayoutAttributeHeight
                                                                      relatedBy:NSLayoutRelationEqual
                                                                         toItem:nil
                                                                      attribute:NSLayoutAttributeNotAnAttribute
                                                                     multiplier:1
                                                                       constant:21.0]];
    [progressViewRight addConstraint:[NSLayoutConstraint constraintWithItem:pttCancelPlayingButton
                                                                      attribute:NSLayoutAttributeWidth
                                                                      relatedBy:NSLayoutRelationEqual
                                                                         toItem:nil
                                                                      attribute:NSLayoutAttributeNotAnAttribute
                                                                     multiplier:1
                                                                       constant:21.0]];
    [progressViewRight addConstraint:[NSLayoutConstraint constraintWithItem:pttCancelPlayingButton
                                                                      attribute:NSLayoutAttributeCenterX
                                                                      relatedBy:NSLayoutRelationEqual
                                                                         toItem:progressViewRight
                                                                      attribute:NSLayoutAttributeCenterX
                                                                     multiplier:1
                                                                       constant:0]];
    [progressViewRight addConstraint:[NSLayoutConstraint constraintWithItem:pttCancelPlayingButton
                                                                      attribute:NSLayoutAttributeCenterY
                                                                      relatedBy:NSLayoutRelationEqual
                                                                         toItem:progressViewRight
                                                                      attribute:NSLayoutAttributeCenterY
                                                                     multiplier:1
                                                                       constant:0]];

adjustsFontSizeToFitWidth
-您是否抱怨顶部和底部被切断?一般来说:通过界面构建器添加约束-调试和设计会更好、更容易。我肯定会抱怨:D.所有东西都是通过代码创建的。我没有将界面生成器用于此视图。好吧,很遗憾,我无法帮助您-也许有阅读代码布局约束经验的人可以。
adjustsFontSizeToFitWidth
。其中的关键字可能是
宽度
,而标签的高度似乎有问题。