How to hide UINavigationBar 1px bottom line

后端 未结 30 2678
不知归路
不知归路 2020-11-22 08:58

I have an app that sometimes needs its navigation bar to blend in with the content.

Does anyone know how to get rid of or to change color of this annoying little ba

30条回答
  •  鱼传尺愫
    2020-11-22 09:40

    Another option if you want to preserve translucency and you don't want to subclass every UINavigationController in your app:

    #import 
    
    @implementation UINavigationController (NoShadow)
    
    + (void)load {
        Method original = class_getInstanceMethod(self, @selector(viewWillAppear:));
        Method swizzled = class_getInstanceMethod(self, @selector(swizzled_viewWillAppear:));
        method_exchangeImplementations(original, swizzled);
    }
    
    + (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;
    }
    
    - (void)swizzled_viewWillAppear:(BOOL)animated {
        UIImageView *shadow = [UINavigationController findHairlineImageViewUnder:self.navigationBar];
        shadow.hidden = YES;
    
        [self swizzled_viewWillAppear:animated];
    }
    
    @end
    

提交回复
热议问题