I have an app, which is intended only for iPad in landscape mode. The screen design is completely done in IB with autolayout.
Now I want to achieve the following behavio
Subclass UILabel, set that class for every uilabel in your Interface Builder.
Create a enum for all different types/fonts you want to support, and create a function in that enum that returns e.g. a font size
Determine the current device and store it in a value from the enum
Override the initializers for your subclassed UILabel in step 1 and get the font size from the variabele defined in step 3, with the vales in step 2
Code:
var currentScreen = Screens.iPadLarge //change this to current device
enum Screens{
case iPadLarge, iPadSmall
func getFont() -> CGFloat{
switch self{
case .iPadLarge:
return 40
case .iPadSmall:
return 20
}
}
}
class MyLabel: UILabel{
init(frame: CGRect){
super.init(frame: frame)
commonLoad()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
commonLoad()
}
func commonLoad(){
let fontSize = currentScreen.getFont()
//use fontSize
}
}