patrikbelis
patrikbelis

Reputation: 1360

Text Color in Navigation Bar Swift

i want to have white text in navigation bar but i still have it black whenever i have code for white font.

    let titleDict: NSDictionary = [NSForegroundColorAttributeName: UIColor.whiteColor()]
    self.navigationController?.navigationBar.titleTextAttributes = titleDict
    self.navigationController?.navigationBar.titleTextAttributes = [ NSFontAttributeName: UIFont(name: "HelveticaNeue-Light", size: 20)]

I tried

self.navigationController?.navigationBar.titleTextAttributes = [ NSFontAttributeName: UIColor.whiteColor()]

but didnt worked

Upvotes: 2

Views: 2621

Answers (1)

Kirsteins
Kirsteins

Reputation: 27335

Seems that you are overwriting the changes each time you set titleTextAttributes. Try to set all attributes at the same time:

self.navigationController?.navigationBar.titleTextAttributes = [        
    NSFontAttributeName: UIFont(name: "HelveticaNeue-Light", size: 20),
    NSForegroundColorAttributeName: UIColor.whiteColor()
]

Upvotes: 7

Related Questions