我最近将 Xcode 更新到 5.1,现在标签栏出现问题。在 iOS 7 和 Xcode 5.0 中,我使用了以下代码:
// Graph tab icon
UITabBar *tabBar = tabBarController.tabBar;
UITabBarItem *graphTabIcon = [tabBar.items objectAtIndex:0];
UIImage *noRenderGraph = [[UIImage imageNamed:@"graph"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
[graphTabIcon setImage:noRenderGraph];
[graphTabIcon setTitle:@"Graph"];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor whiteColor], NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];
// Friends tab icon
UITabBarItem *friendsTabIcon = [tabBar.items objectAtIndex:1];
UIImage *noRenderFriends = [[UIImage imageNamed:@"group"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
[friendsTabIcon setImage:noRenderFriends];
[friendsTabIcon setTitle:@"Friends"];
// Settings tab icon
UITabBarItem *settingsTabIcon = [tabBar.items objectAtIndex:2];
UIImage *noRenderSettings = [[UIImage imageNamed:@"settings"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
[settingsTabIcon setImage:noRenderSettings];
[settingsTabIcon setTitle:@"Settings"];
// Info tab icon
UITabBarItem *infoTabIcon = [tabBar.items objectAtIndex:3];
UIImage *noRenderinfo = [[UIImage imageNamed:@"info"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
[infoTabIcon setImage:noRenderinfo];
[infoTabIcon setTitle:@"Info"];
结果是这样的:
但现在有了 7.1 和 Xcode 5.1,我得到了这个:
我也试过这段代码:
[[UITabBar appearance] setSelectedImageTintColor:[UIColor whiteColor]];
这在 iOS 7.1 上看起来很棒,但在 7 上最终变成了浅棕色。
那么我怎样才能使它适用于两者呢?