@property (nonatomic,strong)UIImageView *imageView;
- (void)viewDidLoad {
UINavigationBar *navigationBar =self.navigationController.navigationBar;
_imageView = [self findHairlineImageViewUnder:navigationBar];
}
- (UIImageView *)findHairlineImageViewUnder:(UIView *)view {
if ([view isKindOfClass:UIImageView.class] && view.bounds.size.height <= 1.0) {
return (UIImageView *)view;
}
for (UIView *subviewin view.subviews) {
UIImageView *imageView = [selffindHairlineImageViewUnder:subview];
if (imageView) {
return imageView;
}
}
return nil;
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.imageView = YES;
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
navBarHairlineImageView.hidden = NO;
}
另外一种方法,在横线位置添加一张透明图片 在viewdidload中调用就可以
- (void)cancleLineOnNavigationBar
{
UINavigationBar *navigationBar =self.navigationController.navigationBar;
[navigationBar setBackgroundImage:[UIImageimageNamed:@"cgClear"]
forBarPosition:UIBarPositionAny
barMetrics:UIBarMetricsDefault];
[navigationBar setShadowImage:[UIImagenew]];
}