I was facing the same problem and solved it using Swifts Computed Properties.
I created a static variable fontsize which gets dynamically initialized with the appropriate fontsize due to the size of the screen.
import UIKit
class ViewFunctions {
let screenSize = UIScreen.mainScreen().bounds.size
static var fontsize: CGFloat {
get {
if screenSize.height >= 1024 { // iPad Pro
return 16.0
} else if screenSize.height >= 768 { // iPad
return 16.0
} else if screenSize.height >= 414 { // iPhone 6Plus
return 15.0
} else if screenSize.height >= 375 { // iPhone 6/s
return 15.0
} else if screenSize.height >= 320 { // iPhone 5/s
return 14.0
} else if screenSize.height >= 319 { // iPhone 4/s
return 14.0
} else {
return 14.0
}
}
}
}
Then use it for example to set the fontsize of a button-label:
import UIKit
class TestClass {
var testButton: UIButton = UIButton(type: UIButtonType.System) as UIButton!
testButton.titleLabel!.font = UIFont(name: "Helvetica Neue", size: ViewFunctions.fontsize)
testButton.setTitle("Test", forState: .Normal)
// add button to view or sth like that...
}