我的TabBar和navigationBar始终是灰色的,尝试了我发现的所有StackOverflow解决方案,但均无效果。他们总是保持灰色。
这是我的AppDelegate
代码,MenuViewController
是TabBarViewController
。
self.window = UIWindow(frame: UIScreen.main.bounds)
let menuVC = MenuViewController()
let navigationController = UINavigationController(rootViewController: menuVC)
navigationController.navigationBar.tintColor = .white
navigationController.navigationBar.barTintColor = .red
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = UINavigationController(rootViewController: MainViewController())
window?.makeKeyAndVisible()
答案 0 :(得分:1)
看一下这段代码:
window?.rootViewController = UINavigationController(rootViewController: MainViewController())
您正在将rootViewController设置为UINavigationController
的另一个实例MainViewController
作为rootViewController。
如果要为样式化的导航控制器提供MenuViewController
实例,则应将其设置为Windows根视图控制器:
let menuVC = MenuViewController()
let navigationController = UINavigationController(rootViewController: menuVC)
navigationController.navigationBar.tintColor = .white
navigationController.navigationBar.barTintColor = .red
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = navigationController
window?.makeKeyAndVisible()