Ulrik. S
Ulrik. S

Reputation: 326

Auto layout constraints not working properly swift 3.0

Kinda new to this whole auto layout constraints part. My app is closing up on a beta and i'm having trouble getting the constraints right. In the picture below i have succesfully managed to add the following constraints to each 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 7 - 7plus and Iphone 4s

Iphone 5 simulator - Notice the labels are cropped and so is the img

What can i do to achieve the same layout behaviour on smaller devices, so that my labels and img does not crop??

Thank you, in advance!

Upvotes: 0

Views: 1446

Answers (2)

mag_zbc
mag_zbc

Reputation: 6982

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.

Upvotes: 1

Fangming
Fangming

Reputation: 25261

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

enter image description here

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

Upvotes: 1

Related Questions