Search code examples
iosobjective-ciphoneautolayout

How to set the autolayout constraints correctly for 4s?


Hi i have screen and i set the constraints but the views are getting misplaced while seeing in the preview... Please suggest me how to set the constraints so that it adjusts all the screens.

For 6s image

But while previewing in 4s it displaces from its position

enter image description here


Solution

  • Case 1 - When height fixed 1. button1- Give constraint lead to margin, top(imageview) and horizontal spacing(button2), fix height. 2. button2- Give constraint top(imageview) and horizontal spacing(button3), fix height. 3. button3- Give constraint top(imageview) and horizontal spacing(button4), fix height. 4. button4- Give constraint top(imageview) and trailing to margin, fix height. 5. Select one button, after press command and select remaining button go to pin option [right side down], select equal widths.

    Case 2 - When height is not fixed 1. button1- Give constraint lead to margin, top(imageview) and horizontal spacing(button2), bottom (bottom layout guide). 2. button2- Give constraint top(imageview) and horizontal spacing(button3), bottom (bottom layout guide). 3. button3- Give constraint top(imageview) and horizontal spacing(button4), bottom (bottom layout guide). 4. button4- Give constraint top(imageview) and trailing to margin, bottom (bottom layout guide). 5. Select one button, after press command and select remaining button go to pin option [right side down], select equal widths and equal heights.

    Note - In second case button height is bigger because we given bottom layout constraint so. In this you can use greater than or equal option for equal height constraint.