ios - UITableViewAutomaticDimension 未正确调整 UIIImageView 的大小

标签 ios swift constraints uitableviewautomaticdimension

我试图根据单元格中的内容(主要是图像)设置 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
}

我的限制: enter image description here

我做错了什么?我将高度和宽度约束设置为“大于或等于”200。 Storyboard 上 UIImageView 的高度和宽度为 370x370

最佳答案

我通过执行以下步骤自己解决了这个问题:

  1. 将我的 Storyboard View 切换到 iPhone SE
  2. 将 UIImageView 设置为“大于或等于”值:275
  3. 将 UIImageView 的宽度和高度的长宽比设置为 1:1

以下是一个图像示例:

enter image description here

关于ios - UITableViewAutomaticDimension 未正确调整 UIIImageView 的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42461186/

相关文章:

ios - 如何在 UISplitViewController 的主视图中添加标签栏

ios - 应用程序状态消息

Swift :Initializer for conditional binding must have Optional type, 不是 'String.SubSequence'(又名 'Substring')

ios - 设置约束时 Collection View 移动得很奇怪

ios - Swift 协议(protocol)委托(delegate)不起作用

html - 带有 iPhone 聊天布局的 CSS

multithreading - swift - 使用 enumerateChildNodesWithName 的多线程错误

ios - 如何通过触摸并按住屏幕的左侧和右侧来移动我的图像? - swift

php - laravel 外键约束格式不正确

Mysql映射表FK约束