UILabel is marked red when "Color Blended Layers" is selected

I have some UILabels, whose backgroundColorwhite or red, and opaque are all.

But when an option is selected in the simulator Color Blended Layers, these UILabels are marked as red, not green.

What other options can cause these problems?

My code is as follows:

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.senderNameLabel = [UILabel mt_labelWithFont:FONT(17) andColor:COLOR_NAV_TITLE];
        self.senderNameLabel.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:self.senderNameLabel];

        self.actionTextLabel = [UILabel mt_labelWithFont:FONT(15) andColor:COLOR_NAV_TITLE];
        self.actionTextLabel.numberOfLines = 5;
        self.actionTextLabel.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:self.actionTextLabel];

        self.notifyDateLabel = [UILabel mt_labelWithFont:FONT(12) andColor:COLOR_NAV_TITLE];
        self.notifyDateLabel.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:self.notifyDateLabel];

        [self setLayoutConstraints];
    }
    return self;
}

- (void)setLayoutConstraints {
    CGFloat offsetX = 70;
    CGFloat offsetY = 15;
    CGFloat maxWidth = SCALE_WITH_RATIO(180);
    [self.senderNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
      make.left.equalTo(self.contentView).offset(offsetX);
      make.top.equalTo(self.contentView).offset(offsetY);
      make.width.mas_lessThanOrEqualTo(maxWidth);
    }];

    offsetY = 12.5;
    maxWidth = SCALE_WITH_RATIO(180);
    [self.actionTextLabel mas_makeConstraints:^(MASConstraintMaker *make) {
      make.top.equalTo(self.senderNameLabel.mas_bottom).offset(offsetY);
      make.left.equalTo(self.senderNameLabel);
      make.width.mas_lessThanOrEqualTo(maxWidth);
    }];

    offsetY = 10;
    CGFloat bottomOffsetY = -15;
    [self.notifyDateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
      make.top.equalTo(self.actionTextLabel.mas_bottom).offset(offsetY);
      make.left.equalTo(self.senderNameLabel);
      make.bottom.equalTo(self.contentView).offset(bottomOffsetY);
    }];
}

- (void)prepareForReuse {
    [super prepareForReuse];

    self.senderNameLabel.text = nil;
    self.actionTextLabel.text = nil;
    self.notifyDateLabel.text = nil;
}

- (void)updateWithMessageModel:(MTUserMessageModel *)model {
    self.senderNameLabel.text = model.senderName;
    self.actionTextLabel.text = model.actionText;
    self.notifyDateLabel.text = model.notifyDate;
}

The auxiliary generation method is UILabelas follows:

+ (UILabel *)mt_labelWithFont:(UIFont *)font andColor:(UIColor *)color {
    UILabel *label = [UILabel new];
    label.font = font;
    label.textColor = color;
    return label;
}

The snapshot from the simulator is as follows. enter image description here

+4
source share
1 answer

Just find a solution:

titleLabel.clipsToBounds = YES;
titleLabel.backgroundColor = [UIColor whiteColor];

Then it will turn green again.


, , UILabel .

, UILabel titleLabel. :

po [[titleLabel layer] sublayers]
+10

Source: https://habr.com/ru/post/1625089/


All Articles