Search code examples
iosios5ios6uitabbaruitabbaritem

UITabBar appearance works on iOS6 but not iOS 5


I have some code to customize the TabBar. I use the appearance framework to do this. The App is iOS 5+ so this should work as far as I understand it. My code looks like this:

NSDictionary *textAttributesNormal = @{
  UITextAttributeTextColor: [UIColor colorWithRed:0.04f green:0.25f blue:0.56f alpha:1.00f],
  UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0, 0)]
};

NSDictionary *textAttributesSelected = @{
  UITextAttributeTextColor: [UIColor colorWithWhite:1.0 alpha:1.0]
};


[[UITabBar appearance] setTintColor:[UIColor colorWithRed:0.53f green:0.76f blue:0.91f alpha:1.00f]];
[[UITabBarItem appearance] setTitleTextAttributes:textAttributesNormal forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:textAttributesSelected forState:UIControlStateSelected];

I do this in the applicationDidFinishLaunching method of the delegate. This code works perfectly on iOS6 and does as intended. But on iOS 5 it does nothing. It neither throws any warnings or errors.

The behavior is the same on the simulator and on the actual device. I can set the tint color in the interface builder and then it will work on iOS5. But I didn't found a way to set the text attributes for the tabbar items via IF.

I appreciate any help or hint! :-)

Best wishes, Thomas


Solution

  • Alright, the appearance code was not the actual problem. As stated I did this in

    - (void)applicationDidFinishLaunching:(UIApplication *)application
    

    The app is a little older and the Apple docs state, that on iOS3+ one should use

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    

    I changed that and now it works as expected.