设置 UINavigationBar 全局颜色,背景颜色,前景颜色 swift 3 4 ios 10 +

来源:互联网 发布:海康无网络视频 编辑:程序博客网 时间:2024/05/16 18:32

全局设置

写在 AppDelegate 中的func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool 方法中

UINavigationBar.appearance().tintColor = Colors.orange //前景色,按钮颜色UINavigationBar.appearance().barTintColor = Colors.orange //背景色,导航条背景色UINavigationBar.appearance().isTranslucent = true // 导航条背景是否透明UINavigationBar.appearance().titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white] // 设置导航条标题颜色,还可以设置其它文字属性,只需要在里面添加对应的属性

非全局设置

写在相应的 ViewController 中即可

navigationController?.navigationBar.tintColor = UIColor.orange  //前景色,按钮颜色navigationController?.navigationBar.barTintColor = UIColor.white //背景色,导航条背景色navigationController?.navigationBar.isTranslucent = true // 导航条背景是否透明navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white] // 设置导航条标题颜色,还可以设置其它文字属性,只需要在里面添加对应的属性

想让图标显示原始颜色请看这里: http://blog.csdn.net/kimbing/article/details/78409733