I need to have two entirely different layouts for portrait and landscape screen in my iOS app. For example in Calculator App in iOS:
Portrait Screen: in Landscape Screen:
This Alternative iOS layouts for portrait and landscape storyboard is not working because I can't find that functionality in XCode 10.X.
Asked
Active
Viewed 292 times
1

Salman Khalid
- 543
- 5
- 23
-
2You can create using Traits and Size Classes. Ref : https://www.techotopia.com/index.php/Using_Trait_Variations_to_Design_Adaptive_iOS_User_Interfaces – Ashish Rana Jun 12 '19 at 13:02
-
Ashish Rana, Using Traits and Size Classes involves constraints, is there any other simple way? – Salman Khalid Jun 12 '19 at 13:28
-
Using stack view you can manage. – Ashish Rana Jun 12 '19 at 14:15
1 Answers
1
The only way I can think of is to place a piece of code to UIViewController.viewDidLayoutSubviews() or UIView.layoutSubviews(). The code could look something like this:
if frame.size.width > frame.size.heigh {
// adjust for landscape
} else {
// adjust for portrait
}
layoutIfNeeded()
Please note that this will not work if you try to do it in viewDidLoad() as the width and height may not be defined at that point. Also, in UIViewController it's 'view.frame.size.width' and view.layoutIfNeeded()
I do something similar to adjust UI for iPhone SE in my app and it works fine.
The "adjusting" can be as simple as changing some constraints or as complex as removing some views and/or adding others.
Also, this is different from "traits". I'd probably advice to explore traits before going down this road.

Antonín Karásek
- 547
- 5
- 16