更新到iOS 7.1后,tabBar图像消失了

时间:2014-03-13 14:47:34

标签: ios ios7 uitabbarcontroller uitabbaritem

在iOS 7.1更新后,我看不到tabBar的图像,但如果我点击一个图像就会出现。 我有以下代码来设置tabBar项目的图像

UINavigationController* myController;

 .. //some code here

 myController.tabBarItem.image = [UIImage imageNamed:@"someImage.png"];
 myController.navigationBar.barTintColor = myColor;
 myController.navigationBar.translucent = NO;

//and so on for the remaining controllers, then I add them to the tabBarController

我搜索了这个问题,我发现我应该添加selectedImage但它不起作用

myController.tabBarItem.selectedImage = [UIImage imageNamed:@"someImage.png"];

有什么想法吗?

我修复了问题检查我的回答

1 个答案:

答案 0 :(得分:2)

我将我的代码更新为以下内容,现在可以使用了。我使用imageWithRenderingMode修复了问题。

//This is the line that I updated 
myController.tabBarItem.image = [[UIImage imageNamed:@"someImage.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];

//And added this line too, I used the same original image not new one for the selected case 
myController.tabBarItem.selectedImage = [UIImage imageNamed:@"someImage.png"];

//The rest of code is the same 

<强>更新

对于多个barItem的情况,请将导航控制器定义如下:

UINavigationController* firstNavigationController;
UINavigationController* secondNavigationController;
UINavigationController* thirdNavigationController;

firstNavigationController = [[UINavigationController alloc] initWithRootViewController:firstViewController]; 
firstNavigationController.tabBarItem.image = [[UIImage imageNamed:@"someImage1.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

secondNavigationController = [[UINavigationController alloc] initWithRootViewController:secondViewController]; 
secondNavigationController.tabBarItem.image = [[UIImage imageNamed:@"someImage2.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

thirdNavigationController = [[UINavigationController alloc] initWithRootViewController:thirdViewController]; 
thirdNavigationController.tabBarItem.image = [[UIImage imageNamed:@"someImage3.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];