swift - Autolayout - 带有 ImageView 的 UITableViewCell - 边距?

标签 swift autolayout

当我尝试在单元格中使用 UIImageView 制作左/上/下边距时,我遇到了问题。它不在乎我会尝试将什么设置为顶部/底部/左侧空间,我总是会得到相同的结果 -> 所有图像都没有任何边距。

我有固定的高度和宽度,我只想添加顶部/左侧边距。

enter image description here

有什么方法可以强制自动布局在这里添加边距吗?

提前感谢您提供任何提示。 编辑: 谢谢你的回答。我试过了,但它仍然无法正常工作。单元格和图像之间始终没有边距:

这是我的约束条件。 (我只需要 8px 作为 superView 的空间)

enter image description here

最佳答案

实际上我无法完全解决这个问题。但我相信,如果您在代码中尝试这些操作,它会成功的。

Using-auto-layout-in-uitableview-for-dynamic-cell-layouts-variable-row-heights

编辑:

将新的 UIImageView 大小和位置设置为下面屏幕截图中显示的值。

enter image description here

现在选择 UIImageView 并添加以下约束。

leadingtopbottom 设置为 20。
宽度高度设置为100。
确保未选中Constrain to margins
点击添加 5 个约束条件按钮。

enter image description here

选择image view 来显示它的约束,然后选择它的bottom 约束来编辑它。在属性编辑器中,将其Relation 更改为大于或等于,并将其Priority 更改为999。

enter image description here

接下来,选择 ImageView 以显示其约束,然后选择其高度 约束。在属性编辑器中,将其 Priority 更改为 999。
同样,选择 ImageView 的宽度约束并将其优先级更改为999。

要设置以下约束,您会得到答案。

关于swift - Autolayout - 带有 ImageView 的 UITableViewCell - 边距?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29669642/

相关文章:

ios - 如何更改导航栏的字体?

ios - 当我将 UIKit 元素添加到 subview 时,setFrame 不起作用

ios - swift : How to make UILabel inherit font size from another UIlabel?

ios - Storyboard 中的 UITableView 不会在旋转时更新内容大小

ios - 在哪里更新自动布局常量?

Xcode 不自动完成 Swift 中的 Parse 函数

swift - swift 协议(protocol)的默认变量逻辑

ios - 无法将类型 'NSTaggedPointerString' 的值转换为 'NSDictionary'。 swift/火力基地

ios - Realm 模型在运行单元测试时不存储任何数据

ios - UITableViewCell 无法将标签约束到右边缘