Navigation bar for split view controller is darker when inside a tab bar controller

前端 未结 3 1998
忘了有多久
忘了有多久 2021-02-06 11:01

If you place a split view controller inside a tab bar controller the navigation bar and tab bar are darker on the left side. I\'ve attached a screenshot. I created this by cre

3条回答
  •  深忆病人
    2021-02-06 11:54

    While other answers get rid of the gray areas, the content doesn't appear behind the bars, making them not translucent in practice. If you wish to keep the effect, I found a workaround: don't use Storyboards.

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    
        let greenVC = UIViewController()
        greenVC.view.backgroundColor = .green
        let redVC = UIViewController()
        redVC.view.backgroundColor = .red
        let splitVC = UISplitViewController()
        splitVC.viewControllers = [UINavigationController(rootViewController: greenVC), UINavigationController(rootViewController: redVC)]
        let rootTBC = UITabBarController()
        rootTBC.viewControllers = [splitVC]
        window?.rootViewController = rootTBC
    
        return true
    }
    

    Before, using stock Interface Builder controllers (notice the gray backdrops of master navigation bar and tab bar):

    After, instantiating controllers in code (see how the backdrops get the right color of the background now):

提交回复
热议问题