I faced a weird problem. I wanted to change the colors of my tabBar in just one of my view controllers of my tabBar. How do I achieve this in iOS > 13?
Asked
Active
Viewed 29 times
1 Answers
0
After searching a lot and finding no working solutions, I succeeded by luck.
I found out that you must set an appearance object before I can change them!!
But if you set appearance before the override function endAppearanceTransition()
of UITabbar it is working, but not anymore. finally, this way worked:
Set an empty appearance object at viewDidLoad of one of the view Controllers or UITabbarViewcontroller to be executed one time:
override func viewDidLoad() { super.viewDidLoad() tabBarController?.tabBar.standardAppearance = UITabBarAppearance() }
Then you can use updating like this at anytime:
let attrs = [NSAttributedString.Key.foregroundColor: UIColor.green] tabBarController?.tabBar.backgroundColor = barColor tabBarController?.tabBar.standardAppearance.stackedLayoutAppearance.selected.iconColor = .green tabBarController?.tabBar.standardAppearance.stackedLayoutAppearance.normal.iconColor = .green tabBarController?.tabBar.standardAppearance.stackedLayoutAppearance.normal.titleTextAttributes = attrs tabBarController?.tabBar.standardAppearance.stackedLayoutAppearance.selected.titleTextAttributes = attrs

Mahdi Moqadasi
- 2,029
- 4
- 26
- 52