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;}
2) add the following to viewDidLoad:
navBarHairlineImageView = [self findHairlineImageViewUnder:self.navigationController.navigationBar];
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;}
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];
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.