在iOS7下设置自定义UITabBar字体颜色

4

在iOS7中,似乎[[UITabBar appearance] setSelectedImageTintColor:[UIColor redColor]];不能正常工作。我可以设置背景图片,但选定的文本不再变为红色。我是从我的应用程序委托中调用这个方法的。有人尝试在iOS7下设置UITabBar字体颜色和样式吗?

3个回答

4

对我来说它起作用了。

[[UITabBar appearance] setBarTintColor:[UIColor blackColor]];
[[UITabBar appearance] setTintColor:[UIColor whiteColor]];

3

在iOS7中,它被称为tintColor,请尝试以下操作:

[[UITabBar appearance] setTintColor:[UIColor redColor]];

编辑:

要对非活动按钮进行着色,请将以下代码放入您的VC的viewDidLoad中:

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

2
为了给未激活的项目上色,我使用了以下方法:
UITabBarItem *item = [self.tabBar.items objectAtIndex:1];

// here you need to use the icon with the color you want, as it will be rendered as it is
item.image = [[UIImage imageNamed:@"unselected.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

// this icon is used for selected tab and it will get tinted as defined in self.tabBar.tintColor
item.selectedImage = [UIImage imageNamed:@"selected.png"];

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接