您的位置:首页 > 移动开发 > Swift

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

2017-11-01 01:06 323 查看

全局设置

写在 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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: