Changing navigation bar color in Swift Changing navigation bar color in Swift ios ios

Changing navigation bar color in Swift


Navigation Bar:

navigationController?.navigationBar.barTintColor = UIColor.green

Replace greenColor with whatever UIColor you want, you can use an RGB too if you prefer.

Navigation Bar Text:

navigationController?.navigationBar.titleTextAttributes = [.foregroundColor: UIColor.orange]

Replace orangeColor with whatever color you like.

Tab Bar:

tabBarController?.tabBar.barTintColor = UIColor.brown

Tab Bar Text:

tabBarController?.tabBar.tintColor = UIColor.yellow

On the last two, replace brownColor and yellowColor with the color of your choice.


Here are some very basic appearance customization that you can apply app wide:

UINavigationBar.appearance().backgroundColor = UIColor.greenColor()UIBarButtonItem.appearance().tintColor = UIColor.magentaColor()//Since iOS 7.0 UITextAttributeTextColor was replaced by NSForegroundColorAttributeNameUINavigationBar.appearance().titleTextAttributes = [UITextAttributeTextColor: UIColor.blueColor()]UITabBar.appearance().backgroundColor = UIColor.yellowColor();

Swift 5.4.2:

UINavigationBar.appearance().backgroundColor = .green // backgorund color with gradient// orUINavigationBar.appearance().barTintColor = .green  // solid color    UIBarButtonItem.appearance().tintColor = .magentaUINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor : UIColor.blue]UITabBar.appearance().barTintColor = .yellow

More about UIAppearance API in Swift you can read here.


Updated for Swift 3, 4, 4.2, 5+

// setup navBar.....UINavigationBar.appearance().barTintColor = .blackUINavigationBar.appearance().tintColor = .whiteUINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]UINavigationBar.appearance().isTranslucent = false

Swift 4

UINavigationBar.appearance().barTintColor = .blackUINavigationBar.appearance().tintColor = .whiteUINavigationBar.appearance().titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]UINavigationBar.appearance().isTranslucent = false

Swift 4.2, 5+

UINavigationBar.appearance().barTintColor = .blackUINavigationBar.appearance().tintColor = .whiteUINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]UINavigationBar.appearance().isTranslucent = false

if you want to work with large title, add this line:

UINavigationBar.navigationBar.prefersLargeTitles = true

Also can check here : https://github.com/hasnine/iOSUtilitiesSource