在我的应用委托(delegate)中,我调用以下代码将每个 VC 的导航栏颜色设置为蓝色。但是,如果用户没有登录,只是想试一试应用程序,我希望导航栏为红色。
UINavigationBar.appearance().barTintColor = UIColor(red: 108.0/255.0, green: 158.0/255.0, blue: 236.0/255.0, alpha: 1.0) // Blue
// UINavigationBar.appearance().barTintColor = UIColor(red: 239.0/255.0, green: 119.0/255.0, blue: 97.0/255.0, alpha: 1.0) // Red
UINavigationBar.appearance().tintColor = .white
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName : UIColor.white]
我将如何根据用户对每个 VC 的选择更改颜色?
最佳答案
像这样在 viewWillAppear
方法中改变每个 VC 的颜色
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)
navigationController?.navigationBar.barTintColor = UIColor(red: 0/255.0, green: 210/255.0, blue: 255/255.0, alpha: 1.0)
}
如果您正在等待某个事件发生,那么您可以在完成后进行更改。像这样
navigationController?.navigationBar.barTintColor = UIColor(red: 0/255.0, green: 210/255.0, blue: 255/255.0, alpha: 1.0)
关于ios - 如何根据用户选择为每个 VC 更改导航栏 Controller 颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41257051/