iOS shows or hides the bottom line of the navigation bar

Source: Internet
Author: User

According to the requirements of the product requirements of the interface to remove the bottom of the navigation bar, the next controller also need to have a bottom line.

Use the following code to implement the

Hide the black line when the page appears

-(void) Viewwillappear: (BOOL) animated

{

[Self.navigationController.navigationBar setbackgroundimage:[uiimage new] forbarmetrics:uibarmetricsdefault];

[Self.navigationController.navigationBar setshadowimage:[uiimage New]];

_navbarhairlineimageview.hidden = YES;

}

Let Navigationbar restore the style when the page disappears

-(void) Viewwilldisappear: (BOOL) animated{

[Self.navigationController.navigationBar Setbackgroundimage:nil Forbarmetrics:uibarmetricsdefault];

[Self.navigationController.navigationBar Setshadowimage:nil];

and define a imageview to equate this black line.

Uiimageview *navbarhairlineimageview;

_navbarhairlineimageview = [self findHairlineImageViewUnder:self.navigationController.navigationBar];

}

The only downside to this method is the translucent (transparent) properties that affect the navigation bar

Method 2: Find the black line and do the processing:

A way to find this black line (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;

}

The same time when the interface appears to open the hidden

-(void) Viewwillappear: (BOOL) animated

//{

_navbarhairlineimageview.hidden = YES;

//}

Let it appear when the page disappears

-(void) Viewdidappear: (BOOL) animated

{

_navbarhairlineimageview.hidden = NO;

}

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.