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

标签 ios swift navigationbar

我想更改导航栏的全局背景颜色。我怎样才能做到这一点?

行:

UINavigationBar.appearance().backgroundColor = UIColor.green

application(_:, didFinishLaunchingWithOptions:)不起作用,同时:

UINavigationBar.appearance().tintColor = UIColor.red

工作正常。

最佳答案

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

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.

关于ios - 如何更改全局导航栏背景颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53559479/

相关文章:

html - 图标不会在导航菜单栏中格式化

iphone - CSS 导航菜单 iPad 和 iPhone

swift - 如何使用 swift 处理 JSON 中丢失的对象?

ios - 访问字典数组的嵌套数组

ios - 测试 UITableViewCell 是否已被删除

iOS:将 OpenAL 的变调和管道输出输出到缓冲区

ios - 仅比较 Date 对象中的时差

jquery - HTML:href to div 然后减去粘性导航栏的高度

ios - 动画 barTintColor 推送 segue

ios - 如何以编程方式设置 UIStackView 占据父 View 的 100% 宽度和高度?