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;

}









阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/saw471/article/details/51565382
上一篇iOS 数组中是否包含某个字符串(BOOL)
下一篇iOS UINavigationController代理方法实现自定义
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭