Open jiangleligejiang opened 5 years ago
UILabel
使用sizeToFit
计算失效问题
可能由于设置了
numberOfLines=0
而导致
UILabel
同时需要设置text
和attributedText
属性时,需要注意将另一者置空处理,且要注意先置空,再赋值,若顺序错误,会导致显示错误
if (model.nicknameHighlight.length > 0) {
self.nicknameLabel.text = nil;
NSDictionary *optoins= @{DTUseiOS6Attributes: @(YES)};
NSData *data = [model.nicknameHighlight dataUsingEncoding:NSUTF8StringEncoding];
NSAttributedString *attributeString = [[NSAttributedString alloc] initWithHTMLData:data
options:optoins
documentAttributes:nil];
self.nicknameLabel.numberOfLines = 1;
self.nicknameLabel.attributedText = attributeString;
self.nicknameLabel.lineBreakMode = NSLineBreakByTruncatingTail; //避免设置富文本后失效
} else {
self.nicknameLabel.attributedText = nil;
self.nicknameLabel.text = model.nickname;
}
富文本相关