Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To change the color of unselected UITabBar icon in iOS 7?

I know this question has been asked earlier as well, but still i didn't get any solution searching the solution on internet.

I referred the following posts:

How can I change the text and icon colors for tabBarItems in iOS 7? Only able to change the selected icons color using tintColor.

How to change the color of unselected tab bar items in iOS 7? In this they have written their own GozTabBar class inherited from UIView

I want to changes the default gray color of UITabBar icon when its in unselected state.

Any help would be highly appreciated. Thanks in advance.

like image 625
Vinay Jain Avatar asked Feb 06 '14 07:02

Vinay Jain


1 Answers

I'm assuming that you do not want to change the color using tintColor? Another option is to use two images that look exactly the same, but differ in color. One image is the selected tab, the other is unselected.

In your AppDelegate.m - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions function, try this.

UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UITabBar *tabBar = tabBarController.tabBar;

// repeat for every tab, but increment the index each time
UITabBarItem *firstTab = [tabBar.items objectAtIndex:0];

// also repeat for every tab
firstTab.image = [[UIImage imageNamed:@"someImage.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
firstTab.selectedImage = [[UIImage imageNamed:@"someImageSelected.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

Edit: For those who don't have the tab bar controller as their root view controller, you can grab the controller like this and the rest of the code is the same.

UITabBarController *tabBarController = self.tabBarController;

like image 140
Inertiatic Avatar answered Sep 20 '22 13:09

Inertiatic