Custom Uitabbar Unselected Item's Color

Custom UITabBar unselected item's color

you can use .AlwaysOriginal

tabBarItem.selectedImage = UIImage(named: "first-selected")!.imageWithRenderingMode(.AlwaysOriginal)

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

Change tintColor of unselected UITabBarController item title and background image

Figured it out!

Use this to change the color of the text:

[[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor greenColor] }
forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor blackColor] }
forState:UIControlStateSelected];

And make sure that image rendering mode is set to ORIGINAL for the images

UIImage *deselectedImage = [[UIImage imageNamed:@"deselectedImage"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImage *selectedImage = [[UIImage imageNamed:@"selectedImage"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

how can I set the tintColor for the tabBar item for the unselected state

You can set the tint color for selected and unselected tab bar buttons like this:

[[UIView appearanceWhenContainedIn:[UITabBar class], nil] setTintColor:[UIColor redColor]];
[[UITabBar appearance] setSelectedImageTintColor:[UIColor greenColor]];

[self calculateFolderSize];
The first line sets the unselected color - red in this example - by setting the UIView's tintColor when it's contained in a tab bar. Note that this only sets the unselected image's tint color - it doesn't change the color of the text below it.

The second line sets the tab bar's selected image tint color to green.

May be it will help you.



Related Topics



Leave a reply



Submit