Search code examples
swiftnavigationitemxcode11.4

Change the title color of a navigation item in Xcode 11.4


I cannot change the title color of a navigation item. It is an old project with support for iOS 10.0+.

Setting the title:

navigationItem.title = "My Title"

Someone changed the property titleColor (in Title Text Attributes) of a navigation bar in a storyboard. And now it doesn't work. It is strange because it works in Xcode 11.3.1, but doesn't work in Xcode 11.4.

Attempts to change the title color:

  1. navigationController?.navigationBar.titleTextAttributes = [ NSAttributedString.Key.foregroundColor: UIColor.mainGold ] (also I tried different keys here)

  2. navigationController?.navigationBar.tintColor = UIColor.mainGold (also tried barTintColor :D)

I tried to add it in viewDidLoad, viewDidAppear, etc

I tried it with UINavigationBar.appeareance() in AppDelegate. And it works in an empty project. It also works for the navigation item title in my first view controller.

There are a lot of screens in my project, and something blocks changing the title color. The title color of a navigation item is always white (for dark theme) or black (for light theme).

It does confuse me.

Screenshot of the view hierarchy. UILabel LUXURIES is the title of a navigation item: enter image description here


Solution

  • I updated Xcode to version 11.4.1 (11E503a) and it fixed the issue.

    I think it was a strange Xcode bug. I tried to reproduce it in an empty project, but I couldn't.