简体   繁体   English

自动布局约束无法正常工作Swift 3.0

[英]Auto layout constraints not working properly swift 3.0

Kinda new to this whole auto layout constraints part. Kinda是这套新的自动布局约束部分。 My app is closing up on a beta and i'm having trouble getting the constraints right. 我的应用程序即将发布Beta版,但我无法正确设置约束。 In the picture below i have succesfully managed to add the following constraints to each object 在下面的图片中,我成功地向每个对象添加了以下约束

  • Horizontally in container 在容器中水平
  • All objects has been pinned top - bottom - left - right to there nearest object. 所有对象都固定在最靠近对象的顶部-底部-左侧-右侧。

As you can see in the picture this behaviour results in fine layout for Iphone 6 and larger but when running on a Iphone 5 simulator or Iphone 4 preview, the layout is bad. 如您在图片中所看到的,此行为会导致Iphone 6及更大版本的布局良好,但在Iphone 5模拟器或Iphone 4预览版上运行时,布局不正确。

Iphone 7-7plus和Iphone 4s

Iphone 5模拟器-注意标签被剪裁,img也被剪裁

What can i do to achieve the same layout behaviour on smaller devices, so that my labels and img does not crop?? 我该怎么做才能在较小的设备上实现相同的布局行为,以使我的标签和img不被裁剪?

Thank you, in advance! 先感谢您!

All you need to do is to make your labels have same width with you view controller and then make sure text shows up in center, like this 您需要做的就是使标签与视图控制器具有相同的宽度,然后确保文本居中显示,就像这样

在此处输入图片说明

With this, you are making sure that the text can be centered and be as long as possible. 这样,您可以确保文本可以居中并尽可能长。 If in this case your label still cannot fully show up, you will need to shrink it. 如果在这种情况下您的标签仍然无法完全显示,则需要缩小标签。 Like calling 喜欢打电话

yourLabel.adjustsFontSizeToFitWidth = true

For each label, keep the horizontal center constraint, but remove the leading and trailing (left and right) constraints. 对于每个标签,保持水平居中约束,但删除前导和尾随(左右)约束。 The label will then automatically resize to fit the content's width. 然后,标签将自动调整大小以适合内容的宽度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM