I have been trying to set both the font size and the font colour of the text in my navigation bar, however I have been having issues.
Basically what seems to be happening is my two lines of code overwrite each other and I can only get them to work on their own.
Here is my code:
self.navigationController?.navigationBar.titleTextAttributes = [NSFontAttributeName: UIFont(name: "Avenir", size: 30)]
self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]
What do I need to change so that I can change the font size and colour?
In swift Mandav's excellent answer could be implemented this way:
var attributes = [
NSForegroundColorAttributeName: UIColor.greenColor(),
NSFontAttributeName: UIFont(name: "Avenir", size: 30)!
]
self.navigationController?.navigationBar.titleTextAttributes = attributes
Note that the UIFont initializer returns an optional because it could fail to find the font, so an exclamation point is used.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With