首先 我们定义个属性
@property (nonatomic, strong)UIImageView *contentLineImageView;
然后写一个方法:
- (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;
}
//然后在viewdidload中调用这个方法
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
_contentLineImageView = [self findHairlineImageViewUnder:self.navigationController.navigationBar];
self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:37/255.0 green:195/255.0 blue:149/255.0 alpha:1.0f];//颜色随便写
//这句话 要写上。 默认是YES可能你得到的颜色与实际的不匹配。 默认为YES 说明是有透明度的。
self.navigationController.navigationBar.translucent = NO;
}
//做了这些操作还不够 我们还需要在viewwillappear 和viewwilldisappear 里写下下面的方法。
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
_contentLineImageView.hidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
_contentLineImageView.hidden = NO;
}