Reputation: 1306
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
}
Upvotes: 0
Views: 254
Reputation: 401
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)
Upvotes: 1