I would like to change the weight of my Tab Bar Item and font when it is selected. I assume this can be done by changing the Tab Bar Item Image and text when the associated tab is being selected. Apart from adjusting the tintcolor of highlighted tab bar items, I can’t seem to find any information customising selected Tab Bar Items online even though most apps (including Instagram) do it. How is this done?
My current 5 tab bars are created in a UITabBarController Class and follow an almost identical formula like this:
let homeController = HomeViewController()
homeController.tabBarItem = UITabBarItem(title: "Home", image: UIImage(named: "home"), tag: 1)
let nav1 = UINavigationController(rootViewController: homeController)
viewControllers = [nav1, nav2, nav3, nav4, nav5]
2
Answers
In order to change the image I simply enter this code in the associated view controller class (in my case they are individuals swift files)
so in viewDidLoad of class HomeViewController: UIViewController {
Programmatically set selected
UITabbarItem
‘s image:You can’t as easily set selected
UITabbarItem
‘s font though. You’d need to create your ownUITabBarController
as shown in this SO thread.