我有2个VC。 在我写这个代码到NavigationController外观但是当我从第二个VC返回到第一个时,我已经把所有东西都弄黑了......
第一个VC:
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.navigationBar.isTranslucent = true
self.navigationController?.navigationBar.barTintColor = UIColor.white
self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.black]
self.navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.black]
self.navigationController?.navigationBar.tintColor = UIColor.init(red:47/255.0, green:158/255.0, blue:249/255.0, alpha: 1.0)
}
第二个VC:
self.navigationController?.navigationBar.isTranslucent = false
self.navigationController?.navigationBar.barTintColor = UIColor.black
self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
self.navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
self.navigationController?.navigationBar.tintColor = UIColor.white
那么为什么当我回到第一个VC时,它不会从viewDidLoad加载颜色?
答案 0 :(得分:1)
由于您的第一个ViewController已加载,请将导航栏设置为override func viewWillAppear() {
super. viewWillAppear()
self.navigationController?.navigationBar.isTranslucent = true
self.navigationController?.navigationBar.barTintColor = UIColor.white
self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.black]
self.navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.black]
self.navigationController?.navigationBar.tintColor = UIColor.init(red:47/255.0, green:158/255.0, blue:249/255.0, alpha: 1.0)
}
♠♥♣♦