一、導(dǎo)航欄屬性設(shè)置
// swift
//返回鍵去掉名字
self.navigationItem.backBarButtonItem = UIBarButtonItem.init(title: "", style: .plain, target: self, action: nil)
// 設(shè)置導(dǎo)航欄item指示色
self.navigationController?.navigationBar.tintColor = UIColor.white
/ /設(shè)置導(dǎo)航欄背景顏色
self.navigationController?.navigationBar.barTintColor = UIColor(red:0.23, green:0.60, blue:0.93, alpha:1.00)
// 設(shè)置導(dǎo)航欄標題顏色
self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
// OC
// 設(shè)置導(dǎo)航欄item指示色
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
// 設(shè)置導(dǎo)航欄標題顏色與大小
self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont boldSystemFontOfSize:17]};
//設(shè)置導(dǎo)航欄背景顏色
self.navigationController.navigationBar.barTintColor = CustomBlueColor;
// 在Appdelegate上設(shè)置導(dǎo)航控欄背景顏色
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:155/255.0 green:131/255.0 blue:255/255.0 alpha:1]];
// 在Appdelegate上標簽欄的背景顏色
[[UITabBar appearance] setBarTintColor:[UIColor colorWithRed:155/255.0 green:131/255.0 blue:255/255.0 alpha:1]];
// 設(shè)置導(dǎo)航欄上文字的顏色
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
// tabbarbutton默認字體顏色
[[UITabBarItem appearance]setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor grayColor]} forState:UIControlStateNormal];
// tabbarbutton選中字體顏色
[[UITabBarItem appearance]setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor orangeColor]} forState:UIControlStateSelected];
二、設(shè)置狀態(tài)欄文字顏色
第一步:在Info.plist中設(shè)置UIViewControllerBasedStatusBarAppearance 為 NO
第二步:在viewDidLoad中加一句
// swift
UIApplication.shared.statusBarStyle = UIStatusBarStyle.lightContent
// OC
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
這樣就可以把默認的黑色改為白色。
設(shè)置狀態(tài)欄背景顏色
// 定義以下方法:
// swift
func setStatusBarBackgroundColor(color : UIColor) {
let statusBarWindow : UIView = UIApplication.shared.value(forKey: "statusBarWindow") as! UIView
let statusBar : UIView = statusBarWindow.value(forKey: "statusBar") as! UIView
if statusBar.responds(to:#selector(setter: UIView.backgroundColor)) {
statusBar.backgroundColor = color
}
}
// 調(diào)用
self.setStatusBarBackgroundColor(color: UIColor(red:0.23, green:0.60, blue:0.93, alpha:1.00))
// OC
- (void)setStatusBarBackgroundColor:(UIColor *)color {
UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
statusBar.backgroundColor = color;
}
}
// 調(diào)用
[self setStatusBarBackgroundColor:CustomBlueColor];