无法在iOS 7中看到所选的按钮图像

时间:2013-12-10 14:29:00

标签: objective-c ios6 ios7 uitabbarcontroller uitabbar

我有app我在哪里使用标签栏控制器。对于标签栏按钮,我的图像大小为30x30和60x60。

当我在iOS 6中运行我的应用程序时,它会显示我选择的图像,但是当我切换到iOS 7时,它不会显示我选择的选项卡图像。知道为什么会这样吗?

以下是相同的截图。

iOS 6

enter image description here

iOS 7

enter image description here


编辑1

在进一步调查中,我发现只有前两个标签栏才会发生这种情况。从第三到第五,iOS7显示图像正常。

使用的代码是

UIImage *selectedImage0 = [UIImage imageNamed:@"home_selected.png"];
UIImage *unselectedImage0 = [UIImage imageNamed:@"home.png"];

UIImage *selectedImage1 = [UIImage imageNamed:@"search_selected.png"];
UIImage *unselectedImage1 = [UIImage imageNamed:@"search.png"];

UIImage *selectedImage2 = [UIImage imageNamed:@"ad_with_us_selected.png"];
UIImage *unselectedImage2 = [UIImage imageNamed:@"ad_with_us.png"];

UIImage *selectedImage3 = [UIImage imageNamed:@"aboutus_selected.png"];
UIImage *unselectedImage3 = [UIImage imageNamed:@"aboutus.png"];

UIImage *selectedImage4 = [UIImage imageNamed:@"contacts_selected.png"];
UIImage *unselectedImage4 = [UIImage imageNamed:@"contacts.png"];

UITabBar *tabBar = self.tabBarController.tabBar;
UITabBarItem *item0 = [tabBar.items objectAtIndex:0];
UITabBarItem *item1 = [tabBar.items objectAtIndex:1];
UITabBarItem *item2 = [tabBar.items objectAtIndex:2];
UITabBarItem *item3 = [tabBar.items objectAtIndex:3];
UITabBarItem *item4 = [tabBar.items objectAtIndex:4];


[[UITabBar appearance] setSelectionIndicatorImage:[[UIImage alloc] init]];

[item0 setFinishedSelectedImage:selectedImage0 withFinishedUnselectedImage:unselectedImage0];
[item1 setFinishedSelectedImage:selectedImage1 withFinishedUnselectedImage:unselectedImage1];
[item2 setFinishedSelectedImage:selectedImage2 withFinishedUnselectedImage:unselectedImage2];
[item3 setFinishedSelectedImage:selectedImage3 withFinishedUnselectedImage:unselectedImage3];
[item4 setFinishedSelectedImage:selectedImage4 withFinishedUnselectedImage:unselectedImage4];

编辑2

以下也不适用于iOS 7。

[tabItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:localize(@"fontNameN") size:10.0f], NSFontAttributeName,  [UIColor greenColor], NSForegroundColorAttributeName,nil] forState:UIControlStateSelected];

forState:UIControlStateHighlighted也是

注意

我在Xcode 4.2中创建了这个项目,现在在iOS 7中,我在Xcode 5中打开了。这会有问题吗?

2 个答案:

答案 0 :(得分:1)

只需使用

[item0 setSelectedImage:selectedImage0];

依此类推,因为

setFinishedSelectedImage:withFinishedUnselectedImage:
iOS 7中

已弃用

答案 1 :(得分:0)

信不信由你

当我从IB中移除TitleImage中默认的文字时,现在一切正常。

enter image description here

Apple只知道问题是什么