Nicholas  Bear
Nicholas Bear

Reputation: 71

Can't change UINavigationBar Custom Font Color

I am using Storyboard and I want to change the UINavigationBar title color to UIColor.whiteColor() on one of my ViewControllers. Xcode is recognizing the font, but I can't change the color.

I Tried: changing it with both Storyboard and with code below, but it does not seem to work. I also tried using different fonts and both .otf and .ttf thinking it might be caused by an error with the fonts. So far I can only get a black color with any custom font.

 var nav = self.navigationController!.navigationBar
    self.navigationItem.title = "HOME"
    nav.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]
    nav.titleTextAttributes = [NSFontAttributeName: UIFont(name: "Impact", size: 30)!]

enter image description here

Upvotes: 1

Views: 355

Answers (2)

BJ Miller
BJ Miller

Reputation: 1548

You can also set the navigation bar's tintColor property to your desired color.

Upvotes: 0

Automate This
Automate This

Reputation: 31394

I found that you need to set the attributes at the same time like this:

nav.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor(), NSFontAttributeName: UIFont(name: "Impact", size: 30)!]

Upvotes: 1

Related Questions