//根据内容长度,调整Lable高度.
+(CGFloat)heightWithContent:(NSString *)string{
NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:16]};
return [string boundingRectWithSize:CGSizeMake([UIScreen mainScreen].bounds.size.width-20, 1000)options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil].size.height;
}
//根据Lable高度调整Cell的高度.
+(CGFloat)heightForRowWithModel:(Model *)model{
return [self heightWithContent:model.content]+50;
}
可视化中:
给lable加约束,只约束距上,左,右,的距离.
cell,在代码中
//给出cell高度预算值
self.tableView.estimatedRowHeight = 100;
//cell高度自己计算
self.tableView.rowHeight= UITableViewAutomaticDimension;