Change text color for large titles

How can I chage the text color for large titles? I want it to be white.

I tried to set the titleTextAttributes like this:

self.navigationController?.navigationBar.prefersLargeTitles = true
self.navigationController?.navigationBar.titleTextAttributes = [
     NSAttributedStringKey.foregroundColor.rawValue: UIColor.white
]


But the text only turns up white when I scroll and it is displayed in the middle as usual.

Accepted Reply

True, it is ignored for the big title.

This is a temporary workaround, call this in your viewDidAppear:

for view in self.navigationController?.navigationBar.subviews ?? [] {
     let subviews = view.subviews
     if subviews.count > 0, let label = subviews[0] as? UILabel {
          label.textColor = <replace with your color>
     }
}

Replies

Seems like an early beta issue - setting the Title Color in a storyboard is also ignored

True, it is ignored for the big title.

This is a temporary workaround, call this in your viewDidAppear:

for view in self.navigationController?.navigationBar.subviews ?? [] {
     let subviews = view.subviews
     if subviews.count > 0, let label = subviews[0] as? UILabel {
          label.textColor = <replace with your color>
     }
}

Works great. I will stick with this solution until official fix.

navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.yellow]

Thank you, works great

Another workaround is to set the style of the notification bar to black.

The way you do this in iOS 13 has changed, you now use UINavigationBarAppearance class

let appearance = UINavigationBarAppearance(idiom: .phone)
appearance.largeTitleTextAttributes = [.foregroundColor: UIColor.red]
appearance.titleTextAttributes = [.foregroundColor: UIColor.red]
appearance.backgroundColor = .white
navigationItem.standardAppearance = appearance
navigationItem.scrollEdgeAppearance = appearance