Home > Software design >  My tabBar disappeared after adding other ViewControllers
My tabBar disappeared after adding other ViewControllers

Time:11-29

It is visible if i comment part where i set my ViewControllers.
It is like been superimposed by other ViewControllers. Cause it works but i can't see it. When i tap bottom parts of screen color of screen changes to colors which i assign to controllers.

enter image description here You have to set image or/and title to your tabbarItem in UIViewControllers.

It's small code example, that helps:

class MusicTabBarController: UITabBarController {
    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.backgroundColor = .gray
        
        let searchVC = SearchViewController()
        searchVC.tabBarItem.title = "SearchViewController"
        let playerVC = ViewController()
        playerVC.tabBarItem.title = "ViewController"
        viewControllers = [
            searchVC,
            playerVC
        ]
    }
}

enter image description here

CodePudding user response:

this piece of code helped to solve my problem

 let appearance = UITabBarAppearance()
    appearance.configureWithOpaqueBackground()
    appearance.backgroundColor = .white
    tabBar.standardAppearance = appearance
    tabBar.scrollEdgeAppearance = tabBar.standardAppearance
  • Related