Twisha Solgama
Twisha Solgama

Reputation: 150

How do i change properties of a navigation bar item programmatically?

This is not a problem. I just want to know if there is a way to change the font color and font size of a navigation bar item programmatically and not through the storyboard. I have a navigation controller setup in the storyboard like so:

StoryBoard

I need to change the color and font size of the label "Flash Chat"

Chat Screen

Each of the view controller is linked to a swift file of same name.

Upvotes: 0

Views: 273

Answers (2)

Can Yoldas
Can Yoldas

Reputation: 212

Use below code to set title attributes in viewDidLoad().

       navigationController?.navigationBar.titleTextAttributes = [.foregroundColor : UIColor.white,
                                                          .font: UIFont.systemFont(ofSize: 16)]

Upvotes: 1

Jayachandra A
Jayachandra A

Reputation: 1342

If your ViewController is attached to NavigationController, then you can use this

self.navigationController?.navigationBar.titleTextAttributes = [.foregroundColor: UIColor.red, .font: UIFont.systemFont(ofSize: 16)]

Upvotes: 0

Related Questions