I created this extension:
import Foundation import UIKit enum SystemFontWeight : String { case UltraLight = "HelveticaNeue-UltraLight" case Thin = "HelveticaNeue-Thin" case Light = "HelveticaNeue-Light" case Regular = "HelveticaNeue" case Medium = "HelveticaNeue-Medium" case Semibold = "Helvetica-Bold" case Bold = "HelveticaNeue-Bold" case Heavy = "HelveticaNeue-CondensedBold" case Black = "HelveticaNeue-CondensedBlack" var weightValue:CGFloat? { if #available(iOS 8.2, *) { switch self { case .UltraLight: return UIFontWeightUltraLight case .Thin: return UIFontWeightThin case .Light: return UIFontWeightLight case .Regular: return UIFontWeightRegular case .Medium: return UIFontWeightMedium case .Semibold: return UIFontWeightSemibold case .Bold: return UIFontWeightBold case .Heavy: return UIFontWeightHeavy case .Black: return UIFontWeightBlack } } else { return nil } } } extension UIFont { static func systemFontOfSize(fontSize:CGFloat, weight:SystemFontWeight) -> UIFont { if #available(iOS 8.2, *) { return UIFont.systemFontOfSize(fontSize, weight: weight.weightValue!) } else {
That allows you to apply the font as follows:
myLabel.font = UIFont.systemFontOfSize(14, weight: .Medium)
This will automatically install the correct font for iOS 8 and iOS 9.
source share