天天看點

設定 UINavigationBar 全局顔色,背景顔色,前景顔色 swift 3 4 ios 10 +

全局設定

寫在 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] // 設定導覽列标題顔色,還可以設定其它文字屬性,隻需要在裡面添加對應的屬性