处理自动布局

时间:2016-09-01 18:27:45

标签: ios autolayout constraints screen nslayoutconstraint

我在约束上浪费了几个小时,我仍然有问题 iPhone 6屏幕,它运行正常,但它无法在iPhone 5/4中运行。我设置所有视图(图像是背景)以修复W / H并点击自动添加缺失约束。

正如你在iPhone 5上看到的那样,它始终是向右,有时向左。我无法添加任何错误。

有任何帮助吗?或者一些该死的好教程:)

enter image description here

1 个答案:

答案 0 :(得分:1)

我只为一行按钮做了一个示例,因此可以将它们重用于其他UI元素。

我将这些约束放在我的按钮上:

LEFT BUTTON:

  • 左前导约束
  • 最高领先约束
  • 身高约束

右键按钮

  • 右尾随约束
  • 最高领先约束
  • 身高约束

与两个按钮相关的约束: (您需要选择两个按钮才能应用关系约束)

  • 按钮之间的间距约束
  • 这些按钮的宽度相等

Interface Builder 中,它看起来像这样:

enter image description here

这些布局是通用,因此我选择了一些设备尺寸:

iPhone 5 enter image description here

iPhone 6 enter image description here

iPhone 6 Plus enter image description here

......等等。