取出導航欄
let bar = UINavigationBar.appearance()
設置導航欄背景色
bar.barTintColor = .white
設置標題顏色和字體大小
bar.titleTextAttributes = [NSAttributedString.Key.font:UIFont.boldSystemFontOfSize(18),NSAttributedString.Key.foregroundColor:UIColor.whiteColor()]
設置布局從導航欄下開始, 把導航欄設置為不透明
bar.isTranslucent = false
bar.shadowImage = UIImage()
設置狀態(tài)欄的字體和圖標的顏色為白色
UIApplication.sharedApplication().setStatusBarStyle(UIStatusBarStyle.LightContent, animated: true)
當然,如果要更改狀態(tài)欄的系統(tǒng)默認設置,就要先獲取修改的權限,方法就是在plist文件里面添加一行設置:View controller-based status bar appearance設為NO,默認是YES。
這里即完成了以上一系列的設置,如果有特定的視圖需要單獨顯示某種顏色,則可以在其viewWillAppear和viewWillDisappear方法里面單獨設置和恢復設置一下即可。