iOS 自定義狀態(tài)欄和導(dǎo)航欄詳細(xì)介紹
iOS 自定義狀態(tài)欄和導(dǎo)航欄
開發(fā)IOS APP 經(jīng)常會(huì)根據(jù)需求更改狀態(tài)欄和導(dǎo)航欄,這里整理了幾種方法,大家可以看下。
導(dǎo)航欄透明
-(void)viewWillAppear:(BOOL)animated { //viewWillAppear中設(shè)置透明
[super viewWillAppear:animated];
[self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault]; //用空?qǐng)D片填充機(jī)位透明
[self.navigationBar setShadowImage:[UIImage new]];//naviBar底部的seperatorLine
}
-(void)viewDidDisappear:(BOOL)animated { //viewWillAppear中設(shè)置恢復(fù)
[super viewDidDisappear:animated];
[self.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
[self.navigationBar setShadowImage:shadowImage];
}
導(dǎo)航欄漸變
barImageView = self.navigationController.navigationBar.subviews.firstObject;
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat minAlphaOffset = - 64;
CGFloat maxAlphaOffset = 200;
CGFloat offset = scrollView.contentOffset.y;
CGFloat alpha = (offset - minAlphaOffset) / (maxAlphaOffset - minAlphaOffset); _barImageView.alpha = alpha;
}
狀態(tài)欄字體顏色改變
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;//黑色 [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;//白色
導(dǎo)航欄隱藏
如果導(dǎo)航欄自定義度高,需要完全自己重寫,可以隱藏原來(lái)的導(dǎo)航欄,并定義一個(gè)新的view
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.navigationController.navigationBarHidden = YES;
}
-(void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
self.navigationController.navigationBarHidden = NO;
}
-(void)ys_initNavigationBar {
self.navigationController.interactivePopGestureRecognizer.delegate = (id)self; // 保留右滑pop的手勢(shì)
_naviBar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, 64)];
_naviBar.backgroundColor = [UIColor whiteColor];
[self.view addSubview:_naviBar];
UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, _naviBar.height-0.5, self.view.width, 0.5)];
line.backgroundColor = [UIColor colorForHex:@"f0f0f0"];
[_naviBar addSubview:line];
// 返回
backButton = [UIButton buttonWithType:UIButtonTypeCustom];
backButton.frame = CGRectMake(0, 20, 44, 44);
[backButton addTarget:self action:@selector(goBack:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:backButton];
// 標(biāo)題
naviLable = [[UIButton alloc] initWithFrame:CGRectMake(44, 20, self.view.width-44*2, 44)];
naviLable.backgroundColor = [UIColor clearColor];
naviLable.font = [UIFont systemFontOfSize:16];
naviLabel.textAlignment = NSTextAlignmentCenter;
[self.view addSubview: naviLable];
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
//navigationBar change
CGFloat minAlphaOffset = 0;
CGFloat maxAlphaOffset = 40;
CGFloat offset = scrollView.contentOffset.y;
CGFloat alpha = (offset - minAlphaOffset) / (maxAlphaOffset - minAlphaOffset);
_naviBar.alpha = alpha;
naviLabel.alpha = alpha;
}
- 詳解在iOS App中自定義和隱藏狀態(tài)欄的方法
- iOS實(shí)現(xiàn)點(diǎn)擊狀態(tài)欄自動(dòng)回到頂部效果詳解
- iOS 隱藏導(dǎo)航條和狀態(tài)欄實(shí)現(xiàn)方法
- 圖文講解如何解決App的iOS 7頂部狀態(tài)欄適配問(wèn)題
- iOS 設(shè)置狀態(tài)欄的背景顏色方法
- 深入理解iOS的狀態(tài)欄
- iOS在狀態(tài)欄上顯示提醒信息的功能定制
- IOS點(diǎn)擊按鈕隱藏狀態(tài)欄詳解及實(shí)例代碼
- IOS 開發(fā)狀態(tài)欄隱藏的實(shí)現(xiàn)辦法
- iOS狀態(tài)欄、導(dǎo)航欄的一些筆記分享
相關(guān)文章
IOS 出現(xiàn)問(wèn)題POST網(wǎng)絡(luò)請(qǐng)求狀態(tài)code:500的解決方法
這篇文章主要介紹了IOS 出現(xiàn)問(wèn)題POST網(wǎng)絡(luò)請(qǐng)求狀態(tài)code:500的解決方法的相關(guān)資料,需要的朋友可以參考下2017-02-02
iphone的safari瀏覽器中實(shí)現(xiàn)全屏瀏覽的方法
這篇文章主要介紹了iphone的safari瀏覽器中實(shí)現(xiàn)全屏瀏覽的方法,同時(shí)介紹了Add to Home Screen功能的實(shí)現(xiàn)方法,需要的朋友可以參考下2014-06-06
iOS密碼在進(jìn)入后臺(tái)1小時(shí)后重新設(shè)置
這篇文章主要介紹了iOS密碼在進(jìn)入后臺(tái)1小時(shí)后重新設(shè)置的相關(guān)資料,需要的朋友可以參考下2017-08-08
iOS 高效的分頁(yè)加載實(shí)現(xiàn)示例
本篇文章主要介紹了iOS 高效的分頁(yè)加載實(shí)現(xiàn)示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-10-10
iOS開發(fā)之App主題切換解決方案完整版(Swift版)
這篇文章主要為大家詳細(xì)介紹了iOS開發(fā)之App主題切換完整解決方案,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-02-02
查看iOS已上架App的Crash信息定位、應(yīng)對(duì)處理方式的實(shí)例
下面小編就為大家?guī)?lái)一篇查看iOS已上架App的Crash信息定位、應(yīng)對(duì)處理方式的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2017-12-12

