iOS自帶的導(dǎo)航欄底部橫線比較粗,有時(shí)候我們想自定義距淫,可以更改粗細(xì)或者顏色之類(lèi)的。
//通過(guò)一個(gè)方法來(lái)找到這個(gè)黑線(findHairlineImageViewUnder):
- (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;
}
在界面出現(xiàn)時(shí)候開(kāi)啟隱藏
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:YES];
_navBarHairlineImageView.hidden = YES;
}
界面消失時(shí)候顯示
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:YES];
_navBarHairlineImageView.hidden = NO;
}
在viewDidLoad中
- (void)viewDidLoad {
[super viewDidLoad];
_navBarHairlineImageView = [self findHairlineImageViewUnder:self.navigationController.navigationBar];
_navBarHairlineImageView.hidden = YES;
UIImageView *navLine = [[UIImageView alloc]initWithFrame:_navBarHairlineImageView.frame];
// navLine.backgroundColor = [UIColor blueColor];
navLine.image = [UIImage imageNamed:@"GrayLine"];//可以對(duì)navLine進(jìn)行操作
[self.navigationController.view addSubview:navLine];
}
在這里我們用自定義的UIimageview代替導(dǎo)航欄底部佑颇。
2019.3.20更新
影藏導(dǎo)航欄底部橫線
self.navigationController.navigationBar.clipsToBounds = YES;