隐藏NavigationBar(导航条)底部分割线

1、定义成员变量

@property (nonatomic, strong) UIImageView *navBarHairlineImageView;

2、创建findHairlineImageViewUnder方法,找到底部横线并在viewDidLoad中调用
- (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;
}

在viewDidLoad中调用

 self.navBarHairlineImageView = [self findHairlineImageViewUnder:self.navigationController.navigationBar];
3、在viewWillAppear方法中隐藏该分割线
self.navBarHairlineImageView.hidden=YES;
4、在viewWillDisappear方法中显示该分割线
self.navBarHairlineImageView.hidden=NO;

你可能感兴趣的:(隐藏NavigationBar(导航条)底部分割线)