Search code examples
iosiphoneipadautolayoutconstraints

Setting proper Constraints to UIView in Portrait and Landscape


This is the first time I'm making an iOS app in both orientations.

I have a UIView placed like in above image.1]

I have set the following constraints: Horizontally Centered, Vertically Centered, Leading and Trailing Space : 8, Height : 265.

I want this UIView to look fullscreen in landscape mode such that Leading, Trailing, Top and Bottom is stuck to all edges.

Please help me in doing it. The above set constraints are not looking proper in landscape. See image below :

enter image description here

The above screenshots are of iPhone 6s size. I need app to support iPad in both orientations too.

These are the constraints already applied by me :

enter image description here

EDIT : After vary for traits is applied :

enter image description here

Portrait constraints are the active one and greyed out ones are applied to landscape. It looks as I want in storyboard but still taking height of portrait during runtime.

EDIT 2: Vary for traits is working on that particular size class but not on all size classes. Please suggest how to set same constraints on all size classes.


Solution

  • select landscape option (below the screen near to setting auto layout pane) then press vary for traits , now give new constraints that you want in landscape mode then select done varying.

    Now you have two different constraints for landscape and portrait mode.