This line is available by default
The first method:
UINavigationBar *navigationBar = self.navigationController.navigationBar;// white.png图片自己下载个纯白色的色块,或者自己ps做一个[navigationBar setBackgroundImage:[UIImage imageNamed:@"white.png"] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];[navigationBar setShadowImage:[UIImage new]];
The post-run effect is as follows (the original gray background color will be replaced by White.png):
PS: This is the only official usage that hides this line, but there is a flaw-removed translucency (translucent)
The second method:
1) Declare the Uiimageview variable and store the bottom horizontal line
@implementationMyViewController { UIImageView *navBarHairlineImageView;}
2) Add in Viewdidload:
navBarHairlineImageView = [selffindHairlineImageViewUnder:navigationBar];
3) Realize the function of finding the bottom horizontal line
- (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 = [selffindHairlineImageViewUnder:subview]; if(imageView) { returnimageView; } } returnnil;}
4) finally processed in the Viewwillappear,viewwilldisappear
- (void)viewWillAppear:(BOOL)animated { [superviewWillAppear:animated]; navBarHairlineImageView.hidden = YES;}- (void)viewWillDisappear:(BOOL)animated { [superviewWillDisappear:animated]; navBarHairlineImageView.hidden = NO;}
The effect is as follows:
PS: The second method can keep bar Translucen
iOS Hidden nav bar 1px bottom horizontal line