【发布时间】:2017-01-24 09:39:19
【问题描述】:
我是 swift 新手,所以我不熟悉自动布局。我有一个图像。图像右侧是标签。到正确标签的距离应该是 8。另外我在图像下方有一个标签。这里的距离也应该是 8。
我希望图片现在会自动调整大小。但是在图片上你可以看到它告诉我约束有问题。可能是因为我没有告诉图像总是使视图中的图片尽可能宽,而不是看它需要多高。但我也不知道如何添加这样的约束。你能帮帮我吗?
图像左上角的约束:
scissor.top = topMargin (so 0 to top)
scissor.leading = leadingMargin (so 0 to left)
剪刀和底部标签之间的约束:
label.top =scissor.bottom + 8 (so distance of 8 between them)
底部标签的约束:
label.bottom = bottomMargin (distance of 0 to bottom)
label.leading = leading.Margin (so dostance of 0 to the left)
右侧标签与剪刀之间的约束:
articleLable.leading = scissor.trailing + 8 (so distance of 8)
右侧标签的约束:
articleLable.top = topMargin
articleLable.trailing = trailingMargin
【问题讨论】:
-
UIImageView 的高度/宽度是多少?根据屏幕大小,它应该是静态的还是动态的?
-
@AhmadF 动态根据屏幕大小和高度自动适应
-
您可以添加您对图像(可能还有标签)的所有约束吗?
-
@BenjaminLowry 添加了约束
-
@Sonius 那么约束错误是什么?它说你需要什么?
标签: swift xcode constraints