iOS UILabel結尾顯示...省略號的做法

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;
}
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容