在项目有时候需要去除掉导航栏下面的黑线,现在附上代码,供大家参考
@property (nonatomic, weak) UIImageView * lineView;
//1.视图加载完成获取到导航栏最下面的黑线
- (void)viewDidLoad {
[super viewDidLoad];
//2.获取导航栏下面的黑线
self.lineView = [self getLineViewInNavigationBar:self.navigationController.navigationBar];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
//3.视图将要显示时隐藏
self.lineView.hidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
//4.视图将要消失时取消隐藏
self.lineView.hidden = NO;
}
//找到导航栏最下面黑线视图
- (UIImageView *)getLineViewInNavigationBar:(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 getLineViewInNavigationBar:subview];
if (imageView) {
return imageView;
}
}
return nil;
}