iOS隐藏导航条1px的底部横线

2019PHP高薪工程师学习路线图....>>>

UINavigationBar *navigationBar = self.navigationController.navigationBar;// white.png图片自己下载个纯白色的色块,或者自己ps做一个
[navigationBar setBackgroundImage:[UIImage imageNamed:@"white.png"] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];[navigationBar setShadowImage:[UIImage new]];

第二种方法:
1)声明UIImageView变量,存储底部横线

1
2
3
@implementationMyViewController {
    UIImageView *navBarHairlineImageView;
}

2)在viewDidLoad中加入:

1
navBarHairlineImageView = [selffindHairlineImageViewUnder:navigationBar];

3)实现找出底部横线的函数

1
2
3
4
5
6
7
8
9
10
11
12
- (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)最后在viewWillAppear,viewWillDisappear中处理

1
2
3
4
5
6
7
8
9
- (void)viewWillAppear:(BOOL)animated {
    [superviewWillAppear:animated];
    navBarHairlineImageView.hidden = YES;
}
 
- (void)viewWillDisappear:(BOOL)animated {
    [superviewWillDisappear:animated];
    navBarHairlineImageView.hidden = NO;
}