【问题标题】:NavigationBar and TabBar background colors are always greyNavigationBar 和 TabBar 背景颜色始终为灰色
【发布时间】:2020-12-26 21:17:24
【问题描述】:

我的 TabBar 和 navigationBar 总是灰色的,尝试了我找到的所有 StackOverflow 解决方案,但没有一个有效。他们总是保持灰色。
这是我的AppDelegate 代码,MenuViewControllerTabBarViewController

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()

【问题讨论】:

    标签: ios swift uinavigationcontroller uitabbarcontroller


    【解决方案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()
    

    【讨论】:

      猜你喜欢
      • 2015-08-12
      • 2022-11-03
      • 2012-06-03
      • 2020-04-11
      • 2015-04-05
      • 1970-01-01
      • 1970-01-01
      • 2013-10-17
      • 2015-06-11
      相关资源
      最近更新 更多