如何更改全局导航栏背景颜色?

How to change global navigationBar background color?

我想更改导航栏的全局背景颜色。我该怎么做?

行:

UINavigationBar.appearance().backgroundColor = UIColor.green

application(_:, didFinishLaunchingWithOptions:) 中不起作用,而:

UINavigationBar.appearance().tintColor = UIColor.red

工作正常。

在这种情况下使用 Tint 颜色:

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.