Search code examples
ios7uitabbarcontrollerxcode5tintcolor

iOS: Tabbar Tint Color


I'm creating a TabBar in code:

self = [super init];

    self.tabBarController = [[UITabBarController alloc]init];
    self.tabBarController.delegate = self;
    self.tabBarController.navigationController.delegate = self;

    //Build Model
    NSArray *topLevelControllers = [self buildTopLevelControllers];
    [self.tabBarController setViewControllers:topLevelControllers animated:NO];

    //Inbox will be lead navigation
    self.tabBarController.selectedIndex = kSelectedIndex;

    [self.view addSubview:self.tabBarController.view];
    self.tabBarController.customizableViewControllers = @[];


    return self;
}

In App Delegate I have the following code for Tint:

[[UIView appearance] setTintColor:[ColorUtils globalTintColor]];

Problem: When the App launches, all the icons in the Tab Bar are tinted with the global color. When I select one and then unselect it, they go back to Grey (images default color).

Desired Result: When the App launches, all the buttons are Grey (Grey is the image color in the PNGs). When I tap on the tab bar icon, the color changes to the global tint color.

Tried: In the App delegate, I have added the following code and it does NOT work:

TabBarVC *tabBarVC = [[TabBarVC alloc]init];
tabBarVC.tabBarController.tabBar.tintColor = [UIColor greyColor];
tabBarVC.tabBarController.tabBar.selectedImageTintColor = [STColorUtils globalTintColor];

[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [ColorUtils globalTintColor]}];


[[UIView appearance] setTintColor:[ColorUtils globalTintColor]];
[self.window setRootViewController:tabBarVC];

However, if I comment out:

//[[UIView appearance] setTintColor:[ColorUtils globalTintColor]];

The icons do appear Grey, but the global tint color is iOS7 default: Blue.


Solution

  • There is a known issue with selectedImageTintColor in iOS 7. Last I checked this has yet to be resolved. So remove -

    tabBarVC.tabBarController.tabBar.selectedImageTintColor = [STColorUtils globalTintColor];
    

    Also you want to use the UITabBar's appearance so replace

    [[UIView appearance] setTintColor:[ColorUtils globalTintColor]];
    

    with

    [[UITabBar appearance] setTintColor:[ColorUtils globalTintColor]];