iOS 去掉UINavigationController(导航控制器)去除底部黑线、改背景颜色或者改为全透明

//  第一种方法

//去掉导航条底部黑线两个方法都要用上 

- (void)viewWillAppear:(BOOL)animated{

    // 改背景图

    [self.navigationController.navigationBarsetBackgroundImage:[UIImageimageNamed:@"0031"]forBarMetrics:(UIBarMetricsDefault)];

    //或者背景图可以为空会是全透明

    [self.navigationController.navigationBarsetBackgroundImage:[UIImagenew] forBarMetrics:UIBarMetricsDefault];


   // 去掉阴影

    [self.navigationController.navigationBarsetShadowImage:[UIImagealloc]];

}

//  第二种方法---------------------------------------------------------------

@property (nonatomic, strong) UIImageView *navBarHairlineImageView;


- (void)viewDidLoad {

    [super viewDidLoad];

     // 去底部黑线

    _navBarHairlineImageView = [self findHairlineImageViewUnder:self.navigationController.navigationBar];

      // 改背景颜色

    [self.navigationController.navigationBar setBarTintColor:[UIColor greenColor]];

}


-(void)viewWillAppear:(BOOL)animated{

    [super viewWillAppear:animated];

    _navBarHairlineImageView.hidden = YES;

}


- (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)viewWillDisappear:(BOOL)animated{

    [super viewWillDisappear:animated];

    _navBarHairlineImageView.hidden = NO;

}









你可能感兴趣的:(导航控制器)