导航条和view颜色如果设置一致,就会看到很明显的黑色横线,影响美观,所以需要隐藏掉,代码如下:
// 隐藏导航栏下方的黑线
UIImageView *navBarHairlineImageView;
navBarHairlineImageView = [self findHairlineImageViewUnder:self.navigationController.navigationBar];
navBarHairlineImageView.hidden = YES;
- (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;
}
参考:
iOS中自定义导航栏底部横线