Paste_Image.png
1. 導(dǎo)航欄調(diào)色那些事兒
小規(guī)律:
- 要設(shè)置內(nèi)容彼城,全找item
- 要修改顏色及文字屬性,找bar
1.1 改變 NavigationBar 的背景顏色
[UINavigationBar appearance].barTintColor = [UIColor blueColor];
//如果使用的是backgroundColor退个,就會(huì)自帶毛玻璃效果
self.navigationBar.backgroundColor = [UIcolor blueColor];
1.2 改變 NavigationBar 的字體顏色
NavigationBar 上面有兩處可以改變字體顏色募壕,一是標(biāo)題,二是左右按鈕的文字语盈。
1.2.1 改變左右按鈕的文字顏色:
[UINavigationBar appearance].tintColor = [UIColor whiteColor];
1.2.2 改變標(biāo)題的文字顏色
- 字典對(duì)應(yīng)了一個(gè)系統(tǒng)自帶的KEY舱馅,就是
- 1,NSFontAttributeName:表示要穿一個(gè)字體UIFont
- 2刀荒,NSForegroundColorAttributeName:表示要傳一個(gè)顏色
[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
1.3 去掉 NavigationBar 下方的陰影
iOS 7 NavigationBar的下方默認(rèn)是有一條陰影的代嗤,如果想要 NavigationBar 和下面內(nèi)容的背景顏色融為一體的話,就要去掉這個(gè)陰影缠借。- 這里需要注意的是干毅,如果圖片傳入的是nil,依然還會(huì)添加默認(rèn)的陰影線泼返。
- 系統(tǒng)判斷是否出現(xiàn)陰影線的標(biāo)準(zhǔn)是:是否傳入照片硝逢。所以我們用[UIImage new]創(chuàng)建了一個(gè)空照片(不是nil)。
[[UINavigationBar appearance] setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];[[UINavigationBar appearance] setShadowImage:[UIImage new]];
1.4 改變 TabBar 的字體顏色
[UITabBarItem.appearance setTitleTextAttributes: @{ NSForegroundColorAttributeName : [UIColor blueColor] } forState:UIControlStateNormal];
[UITabBarItem.appearance setTitleTextAttributes: @{ NSForegroundColorAttributeName : [UIColor whiteColor] } forState:UIControlStateSelected];
1.5 改變 StatusBar 的顏色
iOS7以后绅喉,status bar 的背景顏色變成了透明色渠鸽,而且系統(tǒng)會(huì)根據(jù) app的顏色自動(dòng)改變 status bar 的字體顏色(黑和白)。但是這個(gè)自動(dòng)改變的字體顏色并不一定和所有的 app 都搭配霹疫,比如我們 app 的主題色是稍微淺一丟丟的藍(lán)拱绑,但是系統(tǒng)匹配的 status bar 的字體顏色就是黑色,看起來(lái)就很不爽丽蝎,所以就要強(qiáng)制將其改為白色猎拨。
- 方法一: 在 Info.plist 中的 Information Property List 中添加一個(gè) Key為View controller-based status bar appearance的 item,其 Type 設(shè)為 Boolean屠阻,Value 設(shè)為 NO
- 方法二: 然后在
AppDelegate.mapplication:didFinishLaunchingWithOptions
:中添加突下設(shè)置:
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
1.6 隱藏 StatusBar
有時(shí)候?yàn)榱藢?shí)現(xiàn)沉浸式設(shè)計(jì)红省,比如 app 首次打開的引導(dǎo)頁(yè),需要隱藏整個(gè) StatusBar国觉,方法如下:
- 狀態(tài)欄的高度是20
- 方法一: 和改變 StatusBar 顏色一樣吧恃,在 Info.plist 中的 Information Property List 中添加一個(gè) Key為View controller-based status bar appearance的 item,其 Type 設(shè)為 Boolean麻诀,Value 設(shè)為 NO
- 方法二: 在需要隱藏StatusBar 的
ViewController
中的viewDidLoad
加入以下代碼:
if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) { [self prefersStatusBarHidden]; [self setNeedsStatusBarAppearanceUpdate]; }
- 方法三: 重寫prefersStatusBarHidden:
-(BOOL)prefersStatusBarHidden { return YES;}
- 如果子控制器需要控制狀態(tài)欄痕寓,在全局導(dǎo)航欄控制器下面還需要增加以下方法:
- (UIViewController *)childViewControllerForStatusBarStyle{
return self.topViewController;
}
1.7 給導(dǎo)航欄設(shè)置一張背景圖片
- 這張背景圖片系統(tǒng)默認(rèn)的高度是64
[self.navigationBar setBackgoundImage:[UIImage imageNamed:@"navBar"] forBarMetrics:UIBarMetricsDefault];
1.8 導(dǎo)航欄的半透明效果
- 如果設(shè)置成NO傲醉,tableView就從狀態(tài)欄下面開始。
- 如果是YES呻率,就帶了毛玻璃效果硬毕,tableView就從屏幕的左上角開始了。
- 導(dǎo)航欄的默認(rèn)高度是44.
self.navigationBar.translucent = YES;
1.9 自定義頭部View
self.navigationItem.titleView = [[UILabel alloc] init];
2. 標(biāo)簽欄TableBar那些事兒
2.1 調(diào)色
可以完全參考導(dǎo)航欄的礼仗,幾乎雷同吐咳。
2.2 關(guān)閉半透明效果
- 一旦關(guān)閉標(biāo)簽欄的半透明效果,控制器的view就不會(huì)到達(dá)屏幕最底部了元践,而是到了標(biāo)簽欄的緊上方韭脊。
- 標(biāo)簽欄的默認(rèn)高度是49.
self.tabBar.translucent = NO;