如何根据swift 3中静态表视图中的文本增加标签大小

时间:2017-09-04 06:11:27

标签: uitableview swift3

我在Static TableView中有3个自定义单元格。所有细胞都有不同的高度。但我需要根据内容大小使newsDetail标签的高度动态化。通过设置rowHeight和estimatedRowHeight可以轻松地为动态tableview创建动态。但它对静态TableView没有用。我搜索过但无法找到解决方案,有人请你快速帮助我吗?

1 个答案:

答案 0 :(得分:1)

如果您使用Autolayout,则需要使用

viewDidLoad()估计高度

tableView.estimatedRowHeight = 60.0 //you can provide any
tableView.rowHeight = UITableViewAutomaticDimension

实施委托方法

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

需要在constraint的标签上提供UITableViewCell

TopBottomTrailingLeading无需提供任何修复height约束。 并将numberOfLines改为0

UILabel
相关问题