Search code examples
ios5fontsuitabbaruiappearance

How to customise UITabBar text label?


does anybody know how to use the Appearance proxy object

[[UITabBar appearance] set....];

to customise the color,font and shadow for the selected/unselected label of an UITabBar?

thanks a lot.


Solution

  • By accessing the tab-bar item object of the UITabBar for each UIViewController

    This only works for iOS5.0 or later.

    if ([self.tabBarItem respondsToSelector:@selector(setTitleTextAttributes:)]) {
        NSLog(@"*** Support method(iOS 5): setTitleTextAttributes:");
        [self.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                    [UIFont fontWithName:@"AmericanTypewriter" size:20.0f], UITextAttributeFont,
                                                    [UIColor blackColor], UITextAttributeTextColor,
                                                    [UIColor grayColor], UITextAttributeTextShadowColor,
                                                    [NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)], UITextAttributeTextShadowOffset,
                                                    nil]];
    }
    

    Below 5 https://github.com/boctor/idev-recipes/tree/master/CustomTabBar