I\'ve been trying to find the solution to this for the last week, and I have had no luck after trying every possible solution I could find or think of. Every solution I foun
You can call this function from each controller passing self.tabBarController
and each color you want.
Function :
static func customTabBar(controller: UIViewController?, backgroundColor: String, unselectedColor: String, selectedColor: String) {
if let tabBarController = controller as? UITabBarController {
tabBarController.tabBar.barTintColor = UIColor(hex: backgroundColor)
tabBarController.tabBar.tintColor = UIColor(hex: selectedColor)
tabBarController.tabBar.isTranslucent = false
tabBarController.tabBar.selectedItem?.setTitleTextAttributes([NSAttributedString.Key.foregroundColor:UIColor(hex: selectedColor)], for: UIControl.State.selected)
if #available(iOS 10.0, *) {
tabBarController.tabBar.unselectedItemTintColor = UIColor(hex: unselectedColor)
} else {
// Fallback on earlier versions
}
}
}