How to design iPad Landscape and Portrait screens with different Layouts using Size class. I could find only w-regular and h-regular for both orientations. Example: I need t
For Swift 3 it would look like this:
override func overrideTraitCollection(forChildViewController childViewController: UIViewController) -> UITraitCollection? {
if UI_USER_INTERFACE_IDIOM() == .pad &&
view.bounds.width > view.bounds.height {
let collections = [UITraitCollection(horizontalSizeClass: .regular),
UITraitCollection(verticalSizeClass: .compact)]
return UITraitCollection(traitsFrom: collections)
}
return super.overrideTraitCollection(forChildViewController: childViewController)
}
It will use wRhC instead of wRhR for iPad devices in landscape mode. Put this code to your base view controller, i.e. this rule will work for all controllers that were presented by this one. You can put any additional conditions here... For example, if you want this rule to be working only for specific view controller, your if operator would look like this:
if UI_USER_INTERFACE_IDIOM() == .pad &&
childViewController is YourSpecificViewController &&
view.bounds.width > view.bounds.height {
let collections = [UITraitCollection(horizontalSizeClass: .regular),
UITraitCollection(verticalSizeClass: .compact)]
return UITraitCollection(traitsFrom: collections)
}