我希望海报有一个固定的高度,其余内容应该动态调整大小。第 2 和第 3 部分有文本,其大小应动态决定,即应根据文本内容决定。
仅当屏幕至少滚动 2 次时,内容才会调整大小。这是我在heightforrowat和估计的heightforat中写的代码。
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.section == 0{
return CGFloat(250)
}
else {
return UITableViewAutomaticDimension
}
}
override func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.section == 0{
return CGFloat(250)
}
else {
return UITableViewAutomaticDimension
}
}
最佳答案
一些事情:
你不应该使用
UITableViewAutomaticDimension
作为estimatedHeightForRowAt
的返回值你应该只返回一个固定值。您还需要设置
numberOfLines
到 0 和lineBreakMode
至word wrap
对于所有UILabels
具有动态高度。确保您已为每个
UILabel
正确设置约束让他们正确调整大小。即对其superview
的顶部、底部、前导和尾随约束
关于ios - 加载 View 后,静态 TableView 中的单元格不会立即调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41905836/