在iOS 7中,setSelectedImageTintColor无法正常工作。

10

我正在尝试在iOS 7中设置setSelectedImageTintColor,但它不起作用。这是我在AppDelegate.m中的代码,在didFinishLaunchingWithOptions下面:

UITabBarController *tabBarController = (UITabBarController *) self.window.rootViewController;
UITabBar *tabBar = tabBarController.tabBar;

for (UITabBarItem *item in tabBar.items)
    {
        UIImage *image = item.image;
        UIImage *correctImage = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        item.image = correctImage;
    }

[[UITabBar appearance] setTintColor:[UIColor whiteColor]];
[[UITabBar appearance] setSelectedImageTintColor:[UIColor colorWithRed:44.0/255.0 green:176.0/255.0 blue:28.0/255.0 alpha:1.0]];
[[UITabBar appearance] setBarTintColor:[UIColor colorWithRed:51.0/255.0 green:51.0/255.0 blue:51.0/255.0 alpha:1.0]];

选中时它仍然不会显示selectedImageTintColor。选中时为白色,未选中时为灰色。我做错了什么?

1个回答

15

这是iOS 7中已知的问题。 tintColor用于选定的选项卡图像。完全忽略了selectedImageTintColor。没有办法给未选定的选项卡图片设置色调。

请参阅有关此问题的苹果开发者论坛上的讨论

请向苹果提交错误报告


我猜你可以通过使用带有UIImageRenderingModeAlwaysOriginal模式的UIImage来解决这个问题。 - frangulyan

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