
在开启Color Blended Layers之后,notifyDateLabel是绿色的,其他几个 label 都是红色的。
- (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; } 里面用到的 label 生成方法如下
+ (UILabel *)mt_labelWithFont:(UIFont *)font andColor:(UIColor *)color { UILabel *label = [UILabel new]; label.fOnt= font; label.textColor = color; return label; }
1 buydip 2016-01-20 22:38:42 +08:00 贴代码看看? |
2 xi_lin OP @huoshanhui 已更新代码 |
3 buydip 2016-01-21 10:03:09 +08:00 奇怪,几乎一模一样的操作。 |
4 xi_lin OP @huoshanhui 是啊。。 |
5 lee0100317 2016-01-21 10:37:56 +08:00 应该是无解 中文都会这样 纯英文不会 |
6 xi_lin OP @lee0100317 试了下英文还真是。。原来如此,感谢! |