iOS 自定义导航栏 和状态栏
生活随笔
收集整理的這篇文章主要介紹了
iOS 自定义导航栏 和状态栏
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一.更改狀態欄顏色 (StatusBar)
就是比如導航欄是紅色的狀態欄是綠色的.
要實現這樣的效果其實很簡單,就是添加一個背景view.
簡單的實現過程如下:
1 // 設置導航顏色 可用 2 [self.navigationController.navigationBar setBarTintColor:[UIColor redColor]]; 3 //創建一個高20的假狀態欄 4 UIView *statusBarView = [[UIView alloc] initWithFrame:CGRectMake(0, -20, self.view.bounds.size.width, 20)]; 5 //設置成綠色 6 statusBarView.backgroundColor=[UIColor greenColor]; 7 // 添加到 navigationBar 上 8 [self.navigationController.navigationBar addSubview:statusBarView];
二.自定義 StatusBar 和 NavigationBar 的顏色
再說一下實現導航欄的標題的字體和顏色
效果如下:
代碼如下:
1 // Attributes 屬性
2 NSDictionary *textAttributes=@{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont systemFontOfSize:30]};
3 // 設置導航欄的字體大小 顏色
4 [self.navigationController.navigationBar setTitleTextAttributes:textAttributes];
三.隱藏 NavigationBar 和 StatusBar
效果如下:
代碼如下:
1 // 隱藏NavigationBar(導航欄) 2 // [self.navigationController setNavigationBarHidden:YES]; 3 [self.navigationController setNavigationBarHidden:YES animated:YES];
效果如下:
代碼如下:
1 // 隱藏狀態欄 重寫prefersStatusBarHidden
2 - (BOOL)prefersStatusBarHidden
3 {
4 return YES; // yes 隱藏
5 }
四.狀態欄字體顏色 白色
代碼如下:
方法一:
1 // 設置 狀態欄 字體白色 2 // 默認黑色 UIBarStyleDefault 3 // 白色 UIBarStyleBlack ; UIBarStyleBlackOpaque ; UIBarStyleBlackTranslucent 4 [self.navigationController.navigationBar setBarStyle:UIBarStyleBlack]; 5 //[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
方法二:
1 // 狀態欄字體 白色 重寫preferredStatusBarStyle 方法
2 - (UIStatusBarStyle)preferredStatusBarStyle
3 {
4 // UIStatusBarStyleLightContent 白色
5 // UIStatusBarStyleDefault 黑色
6 return UIStatusBarStyleLightContent;
7 }
五.設置導航欄的背景圖片
效果如下:
代碼如下:
1 //設置導航欄的背景圖片 2 [self.navigationController.navigationBar setTranslucent:YES]; // 設置navigationBar的透明效果 3 [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"導航欄背景圖片"] forBarMetrics:UIBarMetricsDefault];
以上內容參考:
ios開發中UINavigationBar和Status Bar實例應用及隱藏各種bar //http://www.111cn.net/sj/ios8/90056.htm
IOS 實現自定義的導航欄背景以及自定義顏色的狀態欄(支持7.0以及低版本) //http://www.cnblogs.com/wt616/p/3784717.html
文章出處:http://www.cnblogs.com/ting-miao/p/5559922.html
總結
以上是生活随笔為你收集整理的iOS 自定义导航栏 和状态栏的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 阿里P10赵海平跳槽字节跳动:深度解析跳
- 下一篇: geth命令参数详解 1.10.4