iOS removes the line from the bottom of the navigation bar

Source: Internet
Author: User

This line will be available by default

The first method:

Uinavigationbar *navigationbar = Self.navigationController.navigationBar;
White.png picture oneself to download a pure white color block, or own PS do a
[Navigationbar setbackgroundimage:[uiimage imagenamed:@ "White.png"]
                   Forbarposition:uibarpositionany
                       Barmetrics:uibarmetricsdefault];
[Navigationbar setshadowimage:[uiimage New]];

The effect is as follows (where the original gray background color is replaced by white.png):

PS: This is the only official use to hide this line, but there is a flaw-delete the translucency (translucent)

The second method:
1 declare uiimageview variable, store bottom horizontal line

@implementation Myviewcontroller {
    uiimageview *navbarhairlineimageview;
}

2) by adding in Viewdidload:

Navbarhairlineimageview = [self findhairlineimageviewunder:navigationbar];

3) Realize the function of finding the bottom horizontal line

-(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 in the viewwillappear,viewwilldisappear processing

-(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 way to keep bar translucent

This article permanent address: http://blog.it985.com/9808.html
This article comes from IT985 blog, reprint, please indicate the source and corresponding link.

Related Article

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.