2016-02-05 73 views
0

我需要在iOS 8.0上使用UIFont.systemFontOfSize(10, weight: UIFontWeightLight),但它仅适用于iOS 8.2。UIFont.systemFontOfSize与iOS 8.2之前的体重

什么是一种很好的解决方法?

+0

'systemFontOfSize:weight'在iOS8.2以及更高版本和更低版本中可用u需要使用'UIFontDescriptor' –

回答

3

试试这个

使用respondsToSelector找对方法是否可用:

let currentFont: UIFont 
    if UIFont.respondsToSelector("systemFontOfSize:weight:") { 
     print("TRUE") 
     currentFont = .systemFontOfSize(10, weight: UIFontWeightLight) 
    } 
    else { 
     print("FALSE") 
     currentFont = UIFont(name: "HelveticaNeue-Light", size: 10)! 
    } 
5

使用#available表达检查操作系统版本。

if #available(iOS 8, *) { 
    // Add your API code for iOS 8 
} else { 
    // Add your API code for below iOS 8 
}