将视图拆分为四个子视图,宽度为25%

时间:2015-10-15 07:57:01

标签: ios xcode autolayout

enter image description here

我想插入4个Subviews,其中 SuperView的确切宽度为25%。

所以,我的问题是如何使用XCode的Autolayout实现这一目标?在Android中我会使用GridLayout或LinearLayout ......

提前致谢

3 个答案:

答案 0 :(得分:4)

只需设置像这个图像的约束,你就会得到你想要的东西

enter image description here

这是不同屏幕尺寸的预览

enter image description here

答案 1 :(得分:1)

您必须选择所有四个视图,并将顶部,底部,左侧,右侧约束添加到零和相等的宽度约束。

你的约束应该是这样的。

enter image description here

在屏幕截图中,四个视图排列在容器视图上。如果您不想要容器视图,那么您还必须指定高度约束。

答案 2 :(得分:0)

您应该使用ios9和xcode 7.0中引入的UIStackView

这是教程的一个链接,看起来像是android中的线性布局

http://code.tutsplus.com/tutorials/ios-9-getting-started-with-uistackview--cms-24193

还有很多其他方法,因为这是新方法,它有助于减少工作和时间,所以你应该使用它。谢谢