-1

I am attempting to change the color of a navigation title. How can I change the color of a navigation title without doing it in the didFinishLaunchingWithOptions method in the AppDelegate file.

  var viewModel: SignUpViewModel? {
        didSet {
            viewModel?.viewDelegate = self
            title = "Sign Up"
            
        }
    }
  • You can do it from anywhere. Note that the navigation could be the same for multiple view controllers on the stack. See this answer for more info https://stackoverflow.com/a/26076698/3729825 – E. Bogren Dec 15 '21 at 06:25

2 Answers2

1

you can change the navigation bar title color by setting title text attributes

    navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.blue]

you can change the navigation bar buttons color by setting tint color

navigationController?.navigationBar.tintColor = UIColor.blue
salubhayo
  • 53
  • 9
1
public var navigationBarColor = UIColor() {
                didSet {
                    UINavigationBar.appearance().barTintColor = UIColor(red: 234.0/255.0, green: 46.0/255.0, blue: 73.0/255.0, alpha: 1.0)
                    UINavigationBar.appearance().tintColor = UIColor.white
                    UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key
        .foregroundColor : UIColor.white]
                }
            }
Jinal Gor
  • 116
  • 2
  • 4