0

自動レイアウトで、2 つのラベル、プログレス バー、キャンセルする X が付いた小さな通知ボックスを作ろうとしています。フォント スケーリングと同じようにラベルを設定しましたが、一部のラベルが切り取られているように見えます。自動レイアウト コードまたは UILabel コードの結果であるかどうかはわかりません。

発行イメージ

テキストがまったく整列されておらず、Playing in ラベルが完全に切り取られていることがわかります。

関連コード:

    // 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]];
4

0 に答える 0