I have recently updated Xcode to 5.1 and now have issues with the tab bar. In iOS 7 and Xcode 5.0 i used this code:

// 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"];

and the result was this :

enter image description here

But now with 7.1 and Xcode 5.1 I get this : enter image description here

I also tried this code :

[[UITabBar appearance] setSelectedImageTintColor:[UIColor whiteColor]];

and that looked great on iOS 7.1, but on 7 ended up being a slight brown color.

So how can I make it so it works on both?

有帮助吗?

解决方案

Based on Leo Natan's comments I did this :

Edit

I ended up just adding both code snippets together and it works how I want it to

App delegate

{
    // iOS 7 method
    // 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"];

    // iOS 7.1 method
    [[UITabBar appearance] setSelectedImageTintColor:[UIColor whiteColor]];
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top