我正在升级我的应用以符合iOS 7指南。我的主标签栏控制器具有蓝色背景,默认的灰色“未选定”色调使图标几乎不可见。如何更改这些图标的色调?我希望他们是黑色或与蓝色背景形成鲜明对比的东西。
我已经使用window.TintColor = White配置了应用程序范围的色调,但这只会更改所选的颜色。 (与TabBar.TintColor相同)
答案 0 :(得分: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"];