1

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?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
JCode
  • 1,788
  • 3
  • 12
  • 29
  • Why not check if 7.1 and use the code that works there? iOS7.0 has had many issues with the tab bar, and some of these are fixed in 7.1. You can also decide not to add specific support for 7.1, and ask users to upgrade if they see visual anomalies. – Léo Natan Apr 16 '14 at 18:44
  • That would work, but it game me an idea. Do you know how you would tell if device iOS iOS 7.1 or 7? – JCode Apr 16 '14 at 19:32
  • 1
    Check out this answer for a good solution: http://stackoverflow.com/a/5337804/983912 – Léo Natan Apr 16 '14 at 19:42
  • This worked, i wish i could give you your deserved rep – JCode Apr 16 '14 at 20:20

1 Answers1

1

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]];
}
JCode
  • 1,788
  • 3
  • 12
  • 29