iosorientationios-autolayoutsize-classes

iOS : How to properly use Size Classes (or other solution) to have different portrait and landscape layouts?


So far my application only handles landscape orientation, and now I want it to also handle portrait orientation. Almost all the views should end up having very different layouts depending on the orientation, so I thought first of creating another Storyboard and assign it each of them to a specific orientation. But from everything I read from here, it looks like it’s not the right thing to do.

Here is the layout I want to have:

enter image description here

So I tried to use Size Classes instead, but I’m very confused about how it works. For example, I tried this from this existing layout:

final class TestCell: UITableViewCell {
    @IBOutlet weak var headerLabel: UILabel!
    @IBOutlet weak var subtextLabel: UILabel!
}

enter image description here

Changing the orientation, clicking “Vary for traits” based on width, and updating the layout with "Done Varying",

enter image description here

But now when I want to save this, and come back to landscape mode, I end up having the same layout for both orientations:

enter image description here

So what am I doing wrong? Thanks for your help!


Solution

  • Try using Vary for Traits again...

    That should give you what you want.