Change iOS 11 large title color

Viewed 13797

I'm using the new enlarged navigation bar titles in iOS 11. But I can't seem to be able to change the textColor.

I tried doing:

self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor]};

This didn't do anything. Any ideas?

7 Answers

Swift 4.2

self.navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor : UIColor.white]

with named color

self.navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor : UIColor(named: "Teal") ?? UIColor.black]

Swift up through Swift 3.2 (not Swift 4+)

        self.navigationController?.navigationBar.largeTitleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]

Swift 5.6.1

In my Swift 5.6.1 and iOS 15.6.1 the following code worked only.

Add the following codes in ViewDidLoad()

    let appearance = UINavigationBarAppearance(idiom: .phone)
    // Add the color you want in your title
    appearance.largeTitleTextAttributes = [.foregroundColor: UIColor.white]
    appearance.titleTextAttributes = [.foregroundColor: UIColor.white]
    // Add the color you want as your navigation bar color. Otherwise it shows White by default
    appearance.backgroundColor = .purple
    navigationItem.standardAppearance = appearance
    navigationItem.scrollEdgeAppearance = appearance
  let largeTitleTextAttributes: [NSAttributedString.Key: Any] = [.foregroundColor: UIColor.gray20, .font: UIFont.systemFont(ofSize: 24.0, weight: .bold)]
    if #available(iOS 15, *) {
                let navigationBar = navigationController.navigationBar
                let appearance = navigationBar.standardAppearance
                    appearance.largeTitleTextAttributes = largeTitleTextAttributes
                    navigationBar.standardAppearance = appearance
                    navigationBar.scrollEdgeAppearance = appearance
            } else {
                    navigationController.navigationBar.largeTitleTextAttributes = largeTitleTextAttributes
            }
Related