去掉navigationBar下面的一条横线

1.第一种方法
[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
2.第二种方法
@interface BaseViewController (){
UIImageView *navBarHairlineImageView;
}

  • (void)viewDidLoad {
    [super viewDidLoad];
    navBarHairlineImageView = [self findHairlineImageViewUnder:self.navigationController.navigationBar];

    // Do any additional setup after loading the view from its nib.
    }

  • (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)viewWillAppear:(BOOL)animated
    {
    [super viewWillAppear:animated];
    navBarHairlineImageView.hidden = YES;
    }

  • (void)viewWillDisappear:(BOOL)animated
    {
    [super viewWillDisappear:animated];
    navBarHairlineImageView.hidden = NO;
    }

你可能感兴趣的:(去掉navigationBar下面的一条横线)