"Go" ios hide the bottom horizontal line of the Nav bar 1px

Source: Internet
Author: User

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 @implementationMyViewController {    UIImageView *navBarHairlineImageView;}

2) Add in Viewdidload:

1 navBarHairlineImageView = [selffindHairlineImageViewUnder: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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.