Unselected Uitabbar Color

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 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

Custom UITabBar unselected item's color

you can use .AlwaysOriginal

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

ios13 - UITabBar tintColor for unSelectedItem not working

iOS 13 with Xcode 11

if #available(iOS 13, *) {
let appearance = UITabBarAppearance()
appearance.stackedLayoutAppearance.normal.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.black]
appearance.stackedLayoutAppearance.selected.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.red]
appearance.stackedLayoutAppearance.normal.iconColor = UIColor.black
appearance.stackedLayoutAppearance.selected.iconColor = UIColor.red
myTabbar.standardAppearance = appearance
}

Get the color of uitabbaritem with unselected state?

To find out the actual colors for UITabBarItem even without calling any appearance API before use the following code. It queries the view hierarchy and uses the first and the 2nd button for figuring out the actual UIColor. For IOS9 it gives "UIDeviceRGBColorSpace 0 0.478431 1 1" (#007aff in hex) for the selectedColor and "UIDeviceWhiteColorSpace 0.572549 1" (#929292 in hex) for the inactiveColor. This might change of course in future versions. To get a concrete color for an item with tintColors, appeareance etc set use findTabBarLabel() for the actual UITabBar.

static UILabel* findTabBarLabel(UITabBar* tb,NSString* text)
{
for (UIView* btn in tb.subviews) {
if (![btn isKindOfClass:NSClassFromString(@"UITabBarButton")]) {continue;}
for (UIView* sv in btn.subviews) {
if (![sv isKindOfClass:NSClassFromString(@"UITabBarButtonLabel")]) {continue;}
UILabel* l=(UILabel*)sv;
if ([text isEqualToString:l.text]) {
return l;
}
}
}
return nil;
}

static void retrieveTabBarSystemColors()
{
UITabBarController* tc=[[UITabBarController alloc] init];
UITabBarItem* it1=[[UITabBarItem alloc] initWithTitle:@"foo" image:nil tag:1];
UIViewController* vc1=[[UIViewController alloc] init];
vc1.tabBarItem=it1;
UITabBarItem* it2=[[UITabBarItem alloc] initWithTitle:@"bar" image:nil tag:2];
UIViewController* vc2=[[UIViewController alloc] init];
vc2.tabBarItem=it2;
tc.viewControllers=@[vc1,vc2];
UITabBar* tb=tc.tabBar;
UILabel* label1=findTabBarLabel(tb,@"foo");
NSLog(@"Tab bar item active:%@",label1.textColor.description);
UILabel* label2=findTabBarLabel(tb,@"bar");
NSLog(@"Tab bar item inactive color:%@",label2.textColor.description);
}

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];


Related Topics



Leave a reply



Submit