我的导航栏样式存在一些问题。假设我有两个 View Controller 。
VC 1 有一个带有白色文本的橙色条,我的设置如下:
func stylingStuffs(){
self.navigationController?.navigationBar.barTintColor = UIColor(red: 0.94, green: 0.38, blue: 0.24, alpha: 1)
self.navigationController?.navigationBar.backgroundColor = UIColor(red: 0.94, green: 0.38, blue: 0.24, alpha: 1)
self.navigationController?.navigationBar.tintColor = UIColor.white
self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName : UIColor.white]
self.navigationController?.navigationBar.isTranslucent = false
UIApplication.shared.statusBarStyle = .lightContent
}
VC 2 有一个透明的导航栏,其代码是:
func stylingStuffs(){
navigationController?.setNavigationBarHidden(false, animated: true)
navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
self.navigationController?.navigationBar.barTintColor = UIColor(red: 0.94, green: 0.38, blue: 0.24, alpha: 0)
self.navigationController?.navigationBar.backgroundColor = UIColor(red: 0.94, green: 0.38, blue: 0.24, alpha: 0)
navigationController?.navigationBar.shadowImage = UIImage()
navigationController?.navigationBar.isTranslucent = true
navigationController?.navigationBar.tintColor = UIColor.white
self.navigationController?.navigationBar.barStyle = .default
UIApplication.shared.statusBarStyle = .lightContent
}
当我从 VC1 导航到 VC2 时,一切正常,当我从 VC2 导航到 VC1 时,VC1 的导航栏以及状态栏现在都是白色/透明的。
我该如何解决这个问题,或者我想在返回 VC1 后重置样式?
最佳答案
第一个 View VC 1 Controller viewDidAppear
调用stylingStuffs()
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated: animated)
stylingStuffs()
}
@rmaddy评论
You are confused because there is actually only one navigation bar. It is part of the one navigation controller that both view controllers are in
所以需要重置VC 1的导航栏样式
关于ios - 返回上一个 VC 后导航栏会发生变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42374067/