iOS navigationBar导航栏底部与self.view的分界线的隐藏
ios开发中经常碰到各种需求,比如要求导航栏的颜色和self.view的颜色一样,当我们直接设置navigationBar的颜色和view一样时,我们会发现navigationBar还会有一条分割线留下,本文就是介绍怎么隐藏导航栏底部的分割线的。
第一种方法:不会影响导航栏translucent 半透明的显示
首先在viewDidLoad 定义一个 UIImageView *navigationImageView 来存储底部分割线。
UIImageView *navigationImageView = [self findHairlineImageViewUnder:self.navigationController.navigationBar];
self.navigationImageView = navigationImageView;
找到导航栏底部的横线
-(UIImageView *)findHairlineImageViewUnder:(UIView *)view { if ([view isKindOfClass:UIImageView.class] && view.bounds.size.height <= 1.0) { return (UIImageView *)view; } for (UIView *subview in view.subviews) { UIImageView *imageView = [self findHairlineImageViewUnder:subview]; if (imageView) { return imageView; } } return nil; }
在viewWillAppear隐藏分割线,在viewDidDisappear中显示分割线
-(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; self.navigationImageView.hidden = YES; } -(void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; self.navigationImageView.hidden = NO; }
第二种方法:会删除导航栏 translucent 半透明的显示。
// @"navImage" 导航栏的颜色 [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navImage"] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault]; [self.navigationController.navigationBar setShadowImage:[UIImage new]];
-------------------------------------
想要了解更多的做法请访问http://www.4byte.cn/question/448208/how-to-hide-ios7-uinavigationbar-1px-bottom-line.html