Rohit Kanade Rohit Kanade - 1 year ago 153
iOS Question

how to give different constraint in same size class (xcode 8 AutoLayout)

First image for iPhone 6s device: Size class is wCompact - rRegular and constraint Constant is 502

Second image for iPhone 5c: Size class is wCompact - rRegular and constraint Constant is 502

Size class is same and constraint is also same, but getting different height green box.
Does constant should work same for same size classes ?

If not then how i will get same height green box using auto layout? I want green box height = 25% of total height of device

Thanks in advance..

Answer Source

Since you have given the constant distance of green box from bottom so it will maintain that constant distance for all the device.

Secondly you have aligned the top of green box with topLayoutGuide so it will maintain the same for all devices.

So basically top is fixed with topLayout and bottom distance is fixed as 502. And if you run the same on different device having different screen height it will auto-resize your green box height only since other two parameters (top, bottom) are fixed.

Please add the height constraint for your green view as shown in image. It will give you greenViewHeight = 25% of superViewHeight

enter image description here

This is the demo created for your question enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download