我从这个问题中知道了获取细线 View 的方法,它是一个 UIImageView:How to hide iOS7 UINavigationBar 1px bottom line
但是,修改这个 View 的背景颜色是很糟糕的体验, 代码如下:
[[self findHairlineImageViewUnder:self.navigationController.navigationBar] setBackgroundColor:[UIColor colorWithHexString:@"ff0000"]];
findHairlineImageViewUnder 方法来自上面的答案链接
这有效,但并不总是有效,即使放入 viewdidload
、viewwillapear
、viewDidLayoutSubviews
,它也会在某些场景恢复到原始颜色,就像在推送和弹出之后。
所以,请问有没有什么完美的方法可以改变uinavigationbar细线的颜色,谢谢。
最佳答案
现在我发现在 hairline 的 superview 中添加了一个 subview 可以解决问题并且工作正常
UIView* sv= [[UIView alloc] initWithFrame:[self findHairlineImageViewUnder:self.navigationController.navigationBar].frame];
sv.backgroundColor=[UIColor colorWithHexString:@"ff0000"];
[[self findHairlineImageViewUnder:self.navigationController.navigationBar].superview addSubview:sv];
关于ios - uinavigationbar细线颜色怎么修改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32041776/