0
我需要在iOS 8.0上使用UIFont.systemFontOfSize(10, weight: UIFontWeightLight)
,但它僅適用於iOS 8.2。UIFont.systemFontOfSize與iOS 8.2之前的體重
什麼是一種很好的解決方法?
我需要在iOS 8.0上使用UIFont.systemFontOfSize(10, weight: UIFontWeightLight)
,但它僅適用於iOS 8.2。UIFont.systemFontOfSize與iOS 8.2之前的體重
什麼是一種很好的解決方法?
試試這個
使用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)!
}
使用#available
表達檢查操作系統版本。
if #available(iOS 8, *) {
// Add your API code for iOS 8
} else {
// Add your API code for below iOS 8
}
'systemFontOfSize:weight'在iOS8.2以及更高版本和更低版本中可用u需要使用'UIFontDescriptor' –