这里介绍三种方式:
1. 设置navigationBar的背景图片时移除黑线的方法,该方法会使translucent属性失效(不推荐)
[self.navigationController.navigationBar setBackgroundImage:[UIImage new]
forBarPosition:UIBarPositionAny
barMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:[UIImage new]];
2. 设置navigationBar的背景图片或背景色时,使用该方法都可移除黑线,且不会使translucent属性失效(个人推荐)
-(void)useMethodToFindBlackLineAndHind {
UIImageView* blackLineImageView = [self findHairlineImageViewUnder:self.navigationController.navigationBar];
//隐藏黑线(在viewWillAppear时隐藏,在viewWillDisappear时显示)
blackLineImageView.hidden = YES;
}
-(void)useMethodToFindBlackLineAndShow {
UIImageView* blackLineImageView = [self findHairlineImageViewUnder:self.navigationController.navigationBar];
//隐藏黑线(在viewWillAppear时隐藏,在viewWillDisappear时显示)
blackLineImageView.hidden = NO;
}
3. 简单移除黑线方法 (简便)
//设置移除黑线
self.navigationController.navigationBar.clipsToBounds = YES;