Search code examples
iosswiftautolayoutnslayoutconstraint

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

  • 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 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!


Solution

  • 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.