Swift navigation controller black in light mode

96 views Asked by At

faced such an issue that the navigation controller is always black even if I change the appearance to light.

Here is how I create it:

class TabBarController: UITabBarController {

override func viewDidLoad() {
    super.viewDidLoad()

    viewControllers = [
        createViewController(for: AssetViewController(), title: NSLocalizedString("Assets", comment: ""), image: UIImage(systemName: "dollarsign.circle")!),
        createViewController(for: WalletViewController(), title: NSLocalizedString("Wallets", comment: ""), image: UIImage(systemName: "wallet.pass")!),
    ]
}

func createViewController(for rootViewController: UIViewController, title: String, image: UIImage) -> UIViewController {
    let navController = UINavigationController(rootViewController: rootViewController)
    navController.tabBarItem.image = image
    navController.navigationBar.prefersLargeTitles = true

    rootViewController.navigationItem.title = title

    return navController
}

ViewController:

class AssetViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()

    view.backgroundColor = .systemBackground

    self.view = CustomView()
}

enter image description here enter image description here

The other navigation controllers I build the same way, but they are 100% fine. What could be the problem? Thanks.

1

There are 1 answers

0
Artiom On BEST ANSWER

Found the problem. I set the backgroundColor and afterward, I set the custom view. Should switch the order. Still weird why other VCs worked fine.