如何去掉导航器下面的黑线

1.定义一个UIImageView储存这条黑线:

@interface ZJYViewController {

    UIImageView *navBlackLineImageView;

}    

2.定义一个方法遍历导航器中的View,将黑线找到并返回出来

- (UIImageView *)findBlackLineImageViewUnder:(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 findBlackLineImageViewUnder:subview];
        if (imageView) {
            return imageView;
        }
    }
    return nil;
}

 
 

3.在viewDidLoad方法中调用findBlackLineImageView方法,view参数传入自己的导航器,并将方法返回的view用navBlackLineImageView接收

self.navBlackLineImageView = [self findBlackLineImageViewUnder:self.navigationController.navigationBar];

4.最后在本页将要显示时将黑线隐藏,在本页将要消失时将黑线再显示

- (void)viewWillAppear:(BOOL)animated {
    
    self.navBlackLineImageView.hidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated {
    
    self.navBlackLineImageView.hidden = NO;
}





已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页