IOS development-hide (remove) the horizontal line at the bottom of the navigation bar and the ios navigation bar

Source: Internet
Author: User

IOS development-hide (remove) the horizontal line at the bottom of the navigation bar and the ios navigation bar

In most cases, iOS development uses the navigation bar. Because our app navigation bar needs to be the same color as the window next to it, the horizontal line at the bottom of the navigation bar will affect the appearance, LZ uses the following methods. I think it's good. Share it with friends.

1) Declare the UIImageView variable to store the bottom horizontal line

@interface MyViewController {    UIImageView *navBarHairlineImageView;}
  • 1
  • 2
  • 3

2) add the following to viewDidLoad:

navBarHairlineImageView = [self findHairlineImageViewUnder:self.navigationController.navigationBar];
  • 1

3) implement the function of finding the horizontal line at the bottom

- (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
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

4) Finally, process it in viewWillAppear and viewWillDisappear.

- (void)viewWillAppear:(BOOL)animated {    [super viewWillAppear:animated];    navBarHairlineImageView.hidden = YES;}- (void)viewWillDisappear:(BOOL)animated {    [super viewWillDisappear:animated];    navBarHairlineImageView.hidden = NO;}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

The above uses a method that I prefer,

The following is the simplest:

.

UINavigationBar * navigationBar = self. navigationController. navigationBar; // bg.png indicates the desired background color. [NavigationBar setBackgroundImage: [UIImage imageNamed: @ "bg.png"] forBarPosition: UIBarPositionAny barMetrics: UIBarMetricsDefault]; [navigationBar setShadowImage: [UIImage new];
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

This is the only official method to hide this line, but there is a defect-delete transpoliccy (translucent)

In general, the second method is still good. We recommend that you use the second method.

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.