I\'m working with adaptive Layout on iOS 8 and I want to get exactly what the size classes are on viewDidLoad. Any ideas about that?
You can also do it like that in Swift 5
enum DeviceTraitStatus {
///IPAD and others: Width: Regular, Height: Regular
case wRhR
///Any IPHONE Portrait Width: Compact, Height: Regular
case wChR
///IPHONE Plus/Max Landscape Width: Regular, Height: Compact
case wRhC
///IPHONE landscape Width: Compact, Height: Compact
case wChC
static var current:DeviceTraitStatus{
switch (UIScreen.main.traitCollection.horizontalSizeClass, UIScreen.main.traitCollection.verticalSizeClass){
case (UIUserInterfaceSizeClass.regular, UIUserInterfaceSizeClass.regular):
return .wRhR
case (UIUserInterfaceSizeClass.compact, UIUserInterfaceSizeClass.regular):
return .wChR
case (UIUserInterfaceSizeClass.regular, UIUserInterfaceSizeClass.compact):
return .wRhC
case (UIUserInterfaceSizeClass.compact, UIUserInterfaceSizeClass.compact):
return .wChC
default:
return .wChR
}
}
}
The main advantatge is that can be used from not only a UIViewController class dependant and the static method can go into an i.e. Helper class. So you can do somewhere in your code:
let textSize:CGFloat = DeviceTraitStatus.current == .wRhR ? 18:14