iOS 隐藏navigation底部线

修改之前:

iOS 隐藏navigation底部线_第1张图片
Paste_Image.png

修改之后:

黑线隐藏了


iOS 隐藏navigation底部线_第2张图片
Paste_Image.png

代码如下

@interface ViewController ()

@property (nonatomic, strong)UIImageView *navigationLineImageView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    

    
    _navigationLineImageView = [self findHairlineImageViewUnder:self.navigationController.navigationBar];
    
    
    // 系统默认YES 可能你得到的颜色与实际的不匹配  因为默认为YES是有透明度的
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBar.barTintColor = [UIColor orangeColor];
    
    UIView *backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 80)];
    backView.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:backView];
    
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    //不能删 删了 navigation 底下的线还会出现
    self.navigationLineImageView.hidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    self.navigationLineImageView.hidden = NO;
}

- (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;
}

转自http://blog.csdn.net/shave_kevin/article/details/47815105

你可能感兴趣的:(iOS 隐藏navigation底部线)