2016-02-05 21 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 
}