setSelectedImageTintColor在iOS 7中不起作用

时间:2022-09-06 21:16:44

I'm trying to setSelectedImageTintColor in iOS 7, but it's not working. Here's the code that I have in my AppDelegate.m under didFinishLaunchingWithOptions

我想在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]];

It still won't show the selectedImageTintColor. It's white when selected; gray when unselected. What am I doing wrong?

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

1 个解决方案

#1


15  

This is a known issue in iOS 7. The tintColor is used for the selected tab image. The selectedImageTintColor is completely ignored. There is no way to tint unselected tab images.

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

See a discussion on the Apple Developer Forums about this.

请参阅有关此问题的Apple开发者论坛的讨论。

Please file a bug report with Apple.

请向Apple提交错误报告。

#1


15  

This is a known issue in iOS 7. The tintColor is used for the selected tab image. The selectedImageTintColor is completely ignored. There is no way to tint unselected tab images.

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

See a discussion on the Apple Developer Forums about this.

请参阅有关此问题的Apple开发者论坛的讨论。

Please file a bug report with Apple.

请向Apple提交错误报告。