1.普通的UILabel,通過如下設置文字過長顯示不完會顯示省略號:
UILabel *contentLab = [UILabel makeLabelWithTextColor:[UIColor colorWithHexString:@"#56585C"] andTextFontSize:12 andText:@"經濟學博士,中國財政科學研究院博士后。1995年開始從事《經濟法》考試輔導,1998年開始編著…"];
contentLab.numberOfLines = 3;
contentLab.lineBreakMode = NSLineBreakByTruncatingTail;
[UILabel changeLineSpaceForLabel:contentLab WithSpace:4.0];
[bGView addSubview:contentLab];
[contentLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(grayView.mas_bottom).offset(5);
make.left.equalTo(headerImageView.mas_right).offset(10);
make.right.offset(-10);
}];
self.contentLab = contentLab;
2.帶屬性 attributedText的label,比如帶文字間隔功能的Label。在設置完值后需要重新設置一下。
self . titleLabel . lineBreakMode = NSLineBreakByTruncatingTail ;
因為label設置了屬性,導致lineBreakMode失效了,不能正常獲取到行的高度
- (void)setModel:(CETeachersCenterModel *)model{
_model = model;
[self.headerImageView sd_setImageWithURL:[NSURL URLWithString:model.picture] placeholderImage:[UIImage imageNamed:@"pic_placeholder"]];
self.nameLab.text = model.name;
self.contentLab.text = model.intro;
self.contentLab.lineBreakMode = NSLineBreakByTruncatingTail;
}