Before few years ago,It was very hard to make UI in both orientations but now with size classes & Xcode 8 it’s very easy to do.
Let’s understand the basic concept
There are two size classes that can be applied to the horizontal (width) or vertical (height) dimension
- regular
- compact
The iPhone 6 Plus and iPhone 7 Plus are the only iPhone devices with a regular width in landscape orientation as you can see in below image [right side]. The bigger size is always regular and the small size is always compact.
The other iPhone models have a trickier set of size classes to remember. The bigger size of the device is regular in portrait mode, but become compact in landscape mode.
Let’s open main storyboard, at bottom is toolbar appearing with all devices icon repeat to size class.
We will change component position based on orientation.
Portrait Mode
Landscape Mode
First in portrait mode , Drag image view & label in view controller & set content according.
Now, Let go step by step, Make sure you select portrait mode
- Select the vary for traits button in toolbar that will open one dialog pop up. There are two variations height & width.
- Select height & width in pop up that will change toolbar in blue color & also change device icon according size class in panel.
- Set all constraints for ImageView & Label
- Click on done in toolbar panel
Cheers!!!…Here our first step is finished & portrait layout set according size class.
Now we set landscape mode
Now run project & check it.