简体   繁体   中英

UITabBar not showing icons in iOS

I am creating a Tab bar controller after login programmatically. So I use the following code. My problem is that icons not showing in the tab bar.

func makeTabBarController() -> Void {
        
        
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let vc1 = storyboard.instantiateViewController(withIdentifier: "homevcID")
        
        
        let nav1 = UINavigationController()
        nav1.viewControllers = [vc1]
        nav1.tabBarItem = UITabBarItem(title: "Steps", image: UIImage(named: "music.png"), tag: 1)
        
        let vc2 = storyboard.instantiateViewController(withIdentifier: "historyvcID")
        
        let nav2 = UINavigationController()
        nav2.viewControllers = [vc2]
        nav2.tabBarItem = UITabBarItem(title: "History", image: UIImage(named: "music"), tag: 2)
        
        
        let tabBarVc = UITabBarController()
        //tabBarVc.tabBar.barTintColor = .green
        //tabBarVc.tabBar.tintColor = .white
        //tabBarVc.tabBar.unselectedItemTintColor = .systemGray
       // tabBarVc.tabBar.isTranslucent = true
        //
        
        tabBarVc.viewControllers = [vc1, vc2]
        
        window?.rootViewController = tabBarVc
        
    }

在此处输入图片说明

Set a rootViewController for a navigationController like this:

let nav = UINavigationController(rootViewController: vc)

You can try this:

let nav1 = UINavigationController(rootViewController: vc1)
nav1.tabBarItem = UITabBarItem(title: "Steps", image: UIImage(named: "music.png"), tag: 1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM