您的位置:首页 > 其它

cell根据文本标签内容自适应高度

2017-12-16 19:28 337 查看
cell里面的label不能有固定高度,只能添加上下左右的约束,并且只能存在唯一一个这样设置的label,可以有其他view,但其他view需要有明确的高度

label需要属性numberOfLines = 0 和adjustsFontSizeTofitWidth = true

代理设置:

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}


tableview设置:

tb_rule.rowHeight = UITableViewAutomaticDimension
tb_rule.estimatedRowHeight = 80
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: