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
@implementation MyViewController { UIImageView *navBarHairlineImageView;}
2) Add in Viewdidload:
navBarHairlineImageView = [self findHairlineImageViewUnder: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 = [self Findhairlineimageviewunder:subview]; if (imageView) { return imageView;}} return Nil;}
4) finally processed in the Viewwillappear,viewwilldisappear
- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; navBarHairlineImageView.hidden = YES;}- (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; navBarHairlineImageView.hidden = NO;}
PS: The second method can keep bar translucent
iOS removes the line at the bottom of the navigation bar