skip to Main Content

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.

2

Answers


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

    self.navigationController?.navigationBar.titleTextAttributes = [.foregroundColor: UIColor.red, .font: UIFont.systemFont(ofSize: 16)]
    
    Login or Signup to reply.
  2. Use below code to set title attributes in viewDidLoad().

           navigationController?.navigationBar.titleTextAttributes = [.foregroundColor : UIColor.white,
                                                              .font: UIFont.systemFont(ofSize: 16)]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search