To Change the Color of Unselected Uitabbar Icon in iOS 7

How do you change the color of unselected items in a Tab Bar?

Make the icon images Black, if they are white Im not sure it will work. As in the actual image themselves should be black in the assets folder not white.

If you add a tabbar from the story board you can put these line of code in that method in the appDelegate method shown in your post

UITabBar.appearance().barTintColor = UIColor.black
UITabBar.appearance().tintColor = UIColor.red
UITabBar.appearance().unselectedItemTintColor = .white

Unselected UITabBar color?

SO says i cannot delete the accepted answer (i tried), but obviously, there are a lot of upvotes for comments that this doesn't work for iOS 7.

See the other answer below with many more upvotes, or the link in @Liam's comment to this answer.


for iOS 6 only

It should be as simple as this:

[[UITabBar appearance] setTintColor:[UIColor grayColor]]; // for unselected items that are gray
[[UITabBar appearance] setSelectedImageTintColor:[UIColor greenColor]]; // for selected items that are green

How to change the unselected tabbaritem color in iOS7?

This code works on iOS 7.

[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:10.0f],
NSForegroundColorAttributeName : [UIColor colorWithRed:.5 green:.5 blue:.5 alpha:1]
} forState:UIControlStateNormal];

Set foreground color as you like.

To affect also the non selected tabbar icons:

[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor greenColor], UITextAttributeTextColor, nil]
forState:UIControlStateNormal];

If it does not work the only way is with images for selected and unselected states:

// set selected and unselected icons
UITabBarItem *item = [self.tabBar.items objectAtIndex:0];

// this way, the icon gets rendered as it is (thus, it needs to be green in this example)
item.image = [[UIImage imageNamed:@"unselected-icon.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

// this icon is used for selected tab and it will get tinted as defined in self.tabBar.tintColor
item.selectedImage = [UIImage imageNamed:@"selected-icon.png"];

How can I change the text and icon colors for tabBarItems in iOS 7?

There are two things you need to do for this:

1) If you want to customize the TabBar itself, you need to set the barTintColor for the tabBarController:

    // this will generate a black tab bar
tabBarController.tabBar.barTintColor = [UIColor blackColor];

// this will give selected icons and text your apps tint color
tabBarController.tabBar.tintColor = appTintColor; // appTintColor is a UIColor *

2) Set the tabBarItem text appearance for each state that you want to override:

[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:10.0f],
NSForegroundColorAttributeName : appTintColor
} forState:UIControlStateSelected];

// doing this results in an easier to read unselected state then the default iOS 7 one
[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:10.0f],
NSForegroundColorAttributeName : [UIColor colorWithRed:.5 green:.5 blue:.5 alpha:1]
} forState:UIControlStateNormal];

Preserving the original image color of the selected and unselected UITabBar icons

Perfect question, really well explained.

You are not setting imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal for the selected image.

Just should add imageWithRenderingMode:UIImageRenderingModeAlwaysOriginalto the selectedImage:

  item.selectedImage = [[UIImage imageNamed:[imageName stringByAppendingString:@"-selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

Check this other answer.



Related Topics



Leave a reply



Submit