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

Time:07-29

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.

CodePudding user response:

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

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

CodePudding user response:

You can use below code for setting title attributes in viewDidLoad.

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