直接设置navigationBar的shadowImage和backgroundImage, 需先让translucent属性设置为NO
1
2
3
4-(void)removeBlackLine {
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:[UIImage new]];
}循环遍历navigationBar的子视图,找到高度小于1的黑线, 在appear是隐藏, disappear时再显示(推荐)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28@implementation ViewController {
UIImageView *navBarHairlineImageView;
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
navBarHairlineImageView.hidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
navBarHairlineImageView.hidden = NO;
}
- (void)viewDidLoad {
[super viewDidLoad];
navBarHairlineImageView= [self findHairlineImageViewUnder:self.navigationController.navigationBar];
// Do any additional setup after loading the view, typically from a nib.
}
- (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;
}切去超出部分, 此方法会把状态栏给切掉
1
2-(void)useClipsToBoundsRemoveBlackLine { self.navigationController.navigationBar.clipsToBounds = YES;
}
隐藏navigationBar底部的黑线shadowImage
本文标题:隐藏navigationBar底部的黑线shadowImage
文章作者:JunFly
发布时间:2016-09-23, 16:45:49
最后更新:2016-09-23, 17:22:21
原始链接:http://junfly.xyz/2016/09/23/9adbb56f98f1.html
许可协议: "署名-非商用-相同方式共享 4.0" 转载请保留原文链接及作者。