选择“颜色混合图层”时,UILabel 标记为红色
UILabel is marked as red when `Color Blended Layers` is selected
我有一些UILabelbackgroundColor
是白色或者红色,不透明都是YES
但是当在 Simulator 中选择 Color Blended Layers
选项时,这些 UILabel 被标记为红色而不是绿色。
还有哪些选项会导致这些?
我的代码如下:
- (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;
}
生成UILabel
的辅助方法如下:
+ (UILabel *)mt_labelWithFont:(UIFont *)font andColor:(UIColor *)color {
UILabel *label = [UILabel new];
label.font = font;
label.textColor = color;
return label;
}
模拟器截图如下
只要找到解决方案:
titleLabel.clipsToBounds = YES;
titleLabel.backgroundColor = [UIColor whiteColor];
然后又变绿了
我发现link显示中文时UILabel
会有一个额外的子层。
假设您有一个名为 titleLabel
的 UILabel 实例。设置中文或英文文本,并使用调试命令检查子层:
po [[titleLabel layer] sublayers]
我有一些UILabelbackgroundColor
是白色或者红色,不透明都是YES
但是当在 Simulator 中选择 Color Blended Layers
选项时,这些 UILabel 被标记为红色而不是绿色。
还有哪些选项会导致这些?
我的代码如下:
- (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;
}
生成UILabel
的辅助方法如下:
+ (UILabel *)mt_labelWithFont:(UIFont *)font andColor:(UIColor *)color {
UILabel *label = [UILabel new];
label.font = font;
label.textColor = color;
return label;
}
模拟器截图如下
只要找到解决方案:
titleLabel.clipsToBounds = YES;
titleLabel.backgroundColor = [UIColor whiteColor];
然后又变绿了
我发现link显示中文时UILabel
会有一个额外的子层。
假设您有一个名为 titleLabel
的 UILabel 实例。设置中文或英文文本,并使用调试命令检查子层:
po [[titleLabel layer] sublayers]