Code
Code

Reputation: 6251

UIFont.systemFontOfSize with weight before iOS 8.2

I need to use UIFont.systemFontOfSize(10, weight: UIFontWeightLight) on iOS 8.0, but it's only available from iOS 8.2.

What's a good workaround?

Upvotes: 0

Views: 1658

Answers (2)

Nilesh Patel
Nilesh Patel

Reputation: 6394

Use the #available expression for checking OS version.

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

Upvotes: 5

Anbu.Karthik
Anbu.Karthik

Reputation: 82776

try this

use respondsToSelector for find the method is available or not :

    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)!
    }

Upvotes: 4

Related Questions