【发布时间】:2017-02-13 01:45:01
【问题描述】:
当我的项目在 Swift 2 中时,我的代码可以工作:
extension UINavigationController {
func hairLine(hide: Bool) {
//hides hairline at the bottom of the navigationbar
for subview in self.navigationBar.subviews {
if subview.isKind(of: UIImageView.self) {
for hairline in subview.subviews {
if hairline.isKind(of: UIImageView.self) && hairline.bounds.height <= 1.0 {
hairline.isHidden = hide
}
}
}
}
}
}
但现在发生了一些变化,但它不起作用。不确定是因为 Swift 3 还是 iOS10,还是我现在正在使用 7plus 和 6s 进行测试,但它不再有效。我会在其中调用正在显示的视图控制器的 viewWillAppear。我在这里看到一个答案说要使用
UINavigationBar.appearance().shadowImage = UIImage()
UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .default)
但这并没有奏效。我尝试用这 2 行替换旧 hairLine() 的内容,尝试将它们直接放入 viewWillAppear 和 viewDidAppear 但仍然不适合我。
【问题讨论】:
标签: swift swift3 uinavigationbar