This line is available by default
The first method:
123456 |
UINavigationBar *navigationBar =
self
.navigationController.navigationBar;
// white.png图片自己下载个纯白色的色块,或者自己ps做一个
[navigationBar setBackgroundImage:[UIImage imageNamed:
@"white.png"
]
forBarPosition:UIBarPositionAny
barMetrics:UIBarMetricsDefault];
[navigationBar setShadowImage:[UIImage
new
]];
|
The post-run effect is as follows (the original gray background color will be replaced by White.png):
PS: This is the only official usage that hides this line, but there is a flaw-removed translucency (translucent)
The second method:
1) Declare the Uiimageview variable and store the bottom horizontal line
123 |
@implementation MyViewController { UIImageView *navBarHairlineImageView; } |
2) Add in Viewdidload:
1 |
navBarHairlineImageView = [ self findHairlineImageViewUnder:navigationBar]; |
3) Realize the function of finding the bottom horizontal line
123456789101112 |
- (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
;
}
|
4) finally processed in the Viewwillappear,viewwilldisappear
123456789 |
- (
void
)viewWillAppear:(
BOOL
)animated {
[
super viewWillAppear:animated];
navBarHairlineImageView.hidden =
YES
;
}
- (
void
)viewWillDisappear:(
BOOL
)animated {
[
super viewWillDisappear:animated];
navBarHairlineImageView.hidden =
NO
;
}
|
The effect is as follows:
PS: The second method can keep bar translucent
This article originates from IT985 Blog
Permanent address of this article: http://blog.it985.com/9808.html
"Go" ios hide the bottom horizontal line of the Nav bar 1px