self.tableView.estimatedRowHeight = 150;
self.tableView.rowHeight = UITableViewAutomaticDimension
-(NSAttributedString *)getAttributedStringWithString:(NSString *)string lineSpace:(CGFloat)lineSpace {
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineSpacing = lineSpace; // 调整行间距
NSRange range = NSMakeRange(0, [string length]);
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:range];
return attributedString;
}
使用:
self.nameLabel.attributedText = [self getAttributedStringWithString:model.name lineSpace:6];
或者 在retuneCell的里 cell.nameLabel.attributedText = [self getAttributedStringWithString:model.name lineSpace:6];
博客介绍了UITableViewCell自适应高度的设置方法,通过设置estimatedRowHeight和rowHeight实现。还给出了获取带行间距的属性字符串的方法,可用于设置Label的attributedText,以调整Label行高,可在特定场景中直接使用该方法。
7159

被折叠的 条评论
为什么被折叠?



