user31929 user31929 - 6 months ago 19
Objective-C Question

How i can update UITabBarController Appearance in real time?

I can't update uibartint color by pressing a uibutton, it doesn't work. This is my hierarchy:

AppDelegate->HomeViewController (that holds my tabBarController)->ChildViewController


I wanna change UiTabbarController color in real-time by pressing a button inside the ChildViewController. This is the code i use:

UIColor* blu = [UIColor colorWithRed: 0.0/255 green: 161.0/255 blue: 223.0/255 alpha: 1];
[[UIView appearance] setTintColor:blu];
[[UITabBar appearance] setTintColor:blu];
[[UISlider appearance] setTintColor:blu];
[[UINavigationBar appearance] setTintColor:blu];


It doesn't change the color of my tabbar in real-time, it changes the color only if i use it during the init of the tabbar. I have search and tried different solutions:

[self.tabBarController.tabBar setHidden:YES];
[self.tabBarController.tabBar setHidden:NO];


not working in my case

CALayer *layer2 = self.tabBarController.view.layer;
[layer2 setNeedsDisplay];
[layer2 displayIfNeeded];


not working in my case

setNeedsStatusBarAppearanceUpdate


not working in my case.

I have also tried to create a method in appDelegate to contains all this tryings, and i have to tried this method from ChildViewController, instead o calling directly the code. The results are the same.
How i can do to refresh the uitabbar and change the color by pressing a button?

Answer

Try below code

UIColor* blu = [UIColor colorWithRed: 0.0/255 green: 161.0/255 blue: 223.0/255 alpha: 1];

[self.tabBarController setTintColor:blu];