0

I want to change global background color of navigationBar. How can I do this?

The line:

UINavigationBar.appearance().backgroundColor = UIColor.green

in application(_:, didFinishLaunchingWithOptions:) doesn't work, while:

UINavigationBar.appearance().tintColor = UIColor.red

works correctly.

rmaddy
  • 314,917
  • 42
  • 532
  • 579

1 Answers1

0

Use Tint color in this case:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    UINavigationBar.appearance().barTintColor = UIColor.green
    UINavigationBar.appearance().tintColor = UIColor.white
    UINavigationBar.appearance().titleTextAttributes = [NSAttributedStringKey.foregroundColor:UIColor.white]

    return true
}

iOS applies tint color to app icons, tab bars, navigation bars and many other things.

Community
  • 1
  • 1
Shubham Mishra
  • 1,303
  • 13
  • 24