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)

4

1 回答 1

3

我没有测试过,但不幸的是,这个答案看起来是唯一的解决方案 https://stackoverflow.com/a/18433996/1732987

更新:为后代复制代码。

// 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"];
于 2013-09-21T15:44:20.320 回答