Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing UIBarButtonItem font on iOS 13

UIBarButtonItem.appearance().setTitleTextAttributes() doesn't work on iOS 13.

like image 331
Nikola Veljic Avatar asked Sep 21 '19 10:09

Nikola Veljic


1 Answers

The way iOS handles global appearances appears to have changed. You'll need to add a condition check for iOS 13 and above and then add your attributes as shown below.

if #available(iOS 13.0, *) {
    let standard = UINavigationBarAppearance()
    standard.configureWithTransparentBackground()

    // TITLE STYLING
    standard.titleTextAttributes = [.foregroundColor: UIColor.white, .font: "FONTNAME"]

    // NAV BUTTON STYLING
    let button = UIBarButtonItemAppearance(style: .plain)
    button.normal.titleTextAttributes = [.foregroundColor: .white, .font: "FONTNAME"]
    standard.buttonAppearance = button

    let done = UIBarButtonItemAppearance(style: .done)
    done.normal.titleTextAttributes = [.foregroundColor: .white, .font: "FONTNAME"]
    standard.doneButtonAppearance = done

    UINavigationBar.appearance().standardAppearance = standard
} else { 

    // Your previous styling here for 12 and below

}

Check out this post for more. I found it really useful in understanding the new updates.

like image 198
HJDavies Avatar answered Nov 03 '22 23:11

HJDavies