1
[[UITabBar appearance] setTintColor:[UIColor redColor]]; // for unselected items that are red
[[UITabBar appearance] setSelectedImageTintColor:[UIColor greenColor]]; // for selected items that are green

Why is this code not working in iOS 7?

setTintColor works but only changes the "selected"-icon's color, not the unselected ones as it did in earlier iOS versions, which is weird ? setSelectedImageTintColor does'nt work at all anymore ? Is it realy not possible to color icons as you wish anymore?

Also the setSelectionIndicatorImage is not working as intended in the start of the app, what is happening in iOS 7?

Derp herp Apple, why ?

4

5 回答 5

3

从 iOS 7 开始,您必须使用setBarTintColor:设置背景颜色,setTintColor:现在影响前景色。

于 2013-09-22T18:08:06.233 回答
2

Adam Waite 的回答不起作用。iOS7下的setFinishedSelectedImage方法会忽略选中的图片。你需要这样:

UITabBarItem *item1 = _tabBarController.tabBar.items[0];
item1.image = [[UIImage imageNamed:@"item1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
item1.selectedImage = [UIImage imageNamed:@"item1-selected"];
于 2013-10-27T14:44:38.927 回答
1

这不是色调,但你可以用图像来做到这一点:

[self.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"item_seleted.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"item_unselected.png"]];

于 2013-10-15T14:26:22.487 回答
1

这是 iOS 7 中的一个已知问题。tintColor 用于选定的选项卡图像。selectedImageTintColor 被完全忽略。无法为未选择的标签图像着色。

请参阅 Apple 开发者论坛https://devforums.apple.com/message/851126#851126 关于此的讨论。

于 2013-10-11T20:30:23.757 回答
0
for (int i=0; i (smallerthen)arrayOfTabBarItems.count; i++) {

    NSString *unselectedImageName = [NSString stringWithFormat:@"%@.png", arrayOfTabBarItems[i]];

    NSString *selectedImageName = [NSString stringWithFormat:@"%@-pressed.png", arrayOfTabBarItems[i]];

    [tabBarCtrl.tabBar.items[i] setFinishedSelectedImage:[UIImage imageNamed:selectedImageName] withFinishedUnselectedImage:[UIImage imageNamed:unselectedImageName]];
}

这对我有用。

于 2014-02-08T15:51:36.783 回答