我正在我的应用程序中实现暗黑模式。以下是我在双击屏幕时调用的代码:
if darkMode == false {
UINavigationBar.appearance().tintColor = UIColor(hexString: "#3A3A3A")
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName:UIColor.whiteColor()]
UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.LightContent
} else {
UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.Default
UINavigationBar.appearance().barTintColor = UIColor(hexString: "#FFFDF3")
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName:UIColor.blackColor()]
只有我的状态栏更新了,但是当我进入另一个视图并返回到主视图时,导航栏确实更新了。为什么会这样?我做错了什么吗?
func setupForColor(color: UIColor) { navigationBar.tintColor = color if darkMode == true { navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.whiteColor()] UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.LightContent } else { navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.blackColor()] UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.Default } }
- nintyappleif let colorNavigationController = self.navigationController as? ColorNavigationController { if darkMode == true { colorNavigationController.setupForColor(UIColor(hexString: "3A3A3A")!) } else { colorNavigationController.setupForColor(UIColor(hexString: "#FFF8D3")!) } }
- nintyappledarkMode
的布尔值吗? - libec