当我回到我的 main 时,为什么 navigationBar 标题没有将其颜色变为白色UIViewController
?这是简单的代码(viewWillAppear
, viewWillDisappear
),但它不起作用,当我回到这个 VC 时,标题保持绿色。应用程序中的主要颜色也是绿色:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
UIApplication.shared.statusBarStyle = .lightContent
DispatchQueue.main.async {
self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white, NSAttributedStringKey.font: UIFont(name: "Gotham-Medium", size: 20)!]
}
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
UIApplication.shared.statusBarStyle = .default
navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.green, NSAttributedStringKey.font: UIFont(name: "Gotham-Medium", size: 20)!]
}