2

I'm upgrading my app to meet iOS 7 guidelines. My main tab bar controller has a blue background and the default gray "unselected" tint makes the icons nearly invisible. How can I change the tint for these icons? I'd like them to be black or something that contrasts a lot with the blue background.

I've already configured an app-wide tint using window.TintColor = White, but that only changes the selected color. (Same with TabBar.TintColor)

hb.
  • 1,705
  • 5
  • 22
  • 43

1 Answers1

3

I haven't tested it, but this answer looks like it's unfortunately the only solution https://stackoverflow.com/a/18433996/1732987

Update: Copied code for posterity.

// set color of selected icons and text to red
self.tabBar.tintColor = [UIColor redColor];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor redColor], UITextAttributeTextColor, nil] forState:UIControlStateSelected];


// set color of unselected text to green
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor greenColor], UITextAttributeTextColor, nil]
                                     forState:UIControlStateNormal];

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

// this way, the icon gets rendered as it is (thus, it needs to be green in this example)
item0.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
item0.selectedImage = [UIImage imageNamed:@"selected-icon.png"];
Community
  • 1
  • 1
  • I need a solution that works with System items (search, bookmarks, etc.) too. My similar question is at http://stackoverflow.com/questions/19018242/how-to-set-uitabbaritems-unselected-tint-including-system-items-ios7 – Olie Sep 26 '13 at 02:22
  • 1
    This is the only solution, ridiculous – Atma Mar 19 '14 at 03:37