我刚刚使用以下代码删除了导航栏阴影线:
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
self.navigationController?.navigationBar.shadowImage = UIImage()
当我使用此代码并尝试打开属于同一导航 Controller 的另一个页面时,它的导航栏看起来不同。我试图设置相同的导航栏背景颜色和色调颜色,但它不起作用。但是,当我删除这些代码时,我使用的所有页面都可以正常工作。我该如何解决这个问题?
截图:
最佳答案
这是常见的行为。当您设置 backgroundImage 时,则无法设置新颜色。您需要将 setBackgroundImage 设置为 nil,然后在下一个 ViewController 中设置您想要的新颜色。
这个库可以帮你轻松搞定https://github.com/MoZhouqi/KMNavigationBarTransition PS:通过链接查看示例
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
configureAppearance()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
configureAppearance()
}
func configureAppearance() {
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
self.navigationController?.navigationBar.shadowImage = UIImage()
}
}
class SecondViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
configureAppearance()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
configureAppearance()
}
func configureAppearance() {
self.navigationController?.navigationBar.setBackgroundImage(nil, for: UIBarMetrics.default)
self.navigationController?.navigationBar.barTintColor = UIColor.yellow
}
}
关于ios - swift 4 : Navigation Bar looks different for the next page,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47514228/