如何隐藏导航栏下的线

首先 我们定义个属性

@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;

}

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容