iOS 隐藏导航栏下的黑线

时间:2021-06-02 03:27:03

一、找到导航栏下的黑线

// 寻找导航栏下的黑线
- (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;
}

二、调用函数找到黑线

// 找到黑线
UIImageView *navBarHairlineImageView = [self findHairlineImageViewUnder:self.navigationController.navigationBar];

 

三、隐藏和显示黑线

// 隐藏导航栏下的黑线
navBarHairlineImageView.hidden = YES;
// 显示导航栏下的黑线
navBarHairlineImageView.hidden = NO;