下面两段代码都放在UINavigationController 或者自定义的UINavigationController
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
// 运用递归影藏自带的黑线
[self hideBorderInView:self.navigationBar];
// 需要设置成的样子
if (!_navLineV) {
_navLineV = [[UIView alloc]initWithFrame:CGRectMake(0, 44, kScreen_Width, 1.0/ [UIScreen mainScreen].scale)];
_navLineV.backgroundColor = kColorCCC;
_navLineV.backgroundColor = [UIColor redColor];
[self.navigationBar addSubview:_navLineV];
}
}
// 递归 遍历view的subViews 直至隐藏
- (void)hideBorderInView:(UIView *)view{
if ([view isKindOfClass:[UIImageView class]]
&& view.frame.size.height <= 1) {
view.hidden = YES;
}
for (UIView *subView in view.subviews) {
[self hideBorderInView:subView];
}
}
- 设置后的效果
-
image
网友评论