Reputation: 7549
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?
Upvotes: 0
Views: 771
Reputation: 535168
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.
Upvotes: 0
Reputation: 4218
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()]
Upvotes: 3