0

I want to change font and color of my UINavigationBar from the AppDelegate. For this I do:

let appearance = UINavigationBar.appearance()
    appearance.translucent = false
    appearance.titleTextAttributes = [NSFontAttributeName: UIFont(name: "Chalkduster", size: 21)!]
    appearance.barTintColor = UIColor(red: 80/255, green: 185/255, blue: 225/255, alpha: 1)
    appearance.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]

but in this case works just one of them, for example:

if I set at first - Font, at the second - color, it just change color, not font, too. If I set at first - Color, at the second - Font, it just change font, not color, too.

How can I change both of them?

1
  • "I want to change font and color of my UINavigationController" A UINavigationController is not a view. It has no font or color.
    – matt
    Sep 22, 2015 at 15:12

2 Answers 2

3
let appearance = UINavigationBar.appearance()
    appearance.translucent = false
    appearance.barTintColor = UIColor(red: 80/255, green: 185/255, blue: 225/255, alpha: 1)
    appearance.titleTextAttributes = [NSFontAttributeName: UIFont(name: "Chalkduster", size: 21)!, NSForegroundColorAttributeName: UIColor.whiteColor()]
0
0

Think about it. You are saying:

appearance.titleTextAttributes = [NSFontAttributeName: UIFont(name: "Chalkduster", size: 21)!]
appearance.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]

So in the second line you throw away the title text attributes you set in the first line. This is not additive in some magical way: you are replacing what you did in the first line with what you do in the second line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.