How can I change the text color of the Navigation Bar on iOS?


Changing the text color of the navigation bar is tricky and easy at the same time, In this post, we will be seeing how one can change the text color of navigation bar in swift.

So let’s get started,

Embed your view controller in Navigation controller as shown below and name navigation item for that particular controller as a tutorial as shown,

Now navigate to AppDelegate.swift and add below lines in didFinisheLaunchingWithOptions method.

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
   // Override point for customization after application launch.
   let textColor = [NSAttributedString.Key.foregroundColor:UIColor.green]
   UINavigationBar.appearance().titleTextAttributes = textColor
   return true
}

Run the app, to see the effect we’ve changed the color to green here.


Updated on: 30-Aug-2019

570 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements