我试图根据单元格中的内容(主要是图像)设置 UITableViewCell 高度。它在 iPhone 7 Plus 上看起来不错,但是任何较小的设备都会产生类似 this 的内容。 。
我在MainViewController
中的代码:
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
我做错了什么?我将高度和宽度约束设置为“大于或等于”200。 Storyboard 上 UIImageView 的高度和宽度为 370x370
最佳答案
我通过执行以下步骤自己解决了这个问题:
- 将我的 Storyboard View 切换到 iPhone SE
- 将 UIImageView 设置为“大于或等于”值:275
- 将 UIImageView 的宽度和高度的长宽比设置为 1:1
以下是一个图像示例:
关于ios - UITableViewAutomaticDimension 未正确调整 UIIImageView 的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42461186/