setSelectedImageTintColor 在 iOS 7 中不起作用
Posted
技术标签:
【中文标题】setSelectedImageTintColor 在 iOS 7 中不起作用【英文标题】:setSelectedImageTintColor not working in iOS 7 【发布时间】:2013-10-10 21:59:55 【问题描述】:我正在尝试在 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】:这是 iOS 7 中的一个已知问题。tintColor
用于选定的标签图像。 selectedImageTintColor
被完全忽略。无法为未选择的标签图像着色。
请参阅discussion on the Apple Developer Forums 了解此内容。
请提交bug report with Apple。
【讨论】:
我想你可以通过使用UIImage
和UIImageRenderingModeAlwaysOriginal
模式来解决这个问题。以上是关于setSelectedImageTintColor 在 iOS 7 中不起作用的主要内容,如果未能解决你的问题,请参考以下文章