Do you mean this? Keep in mind that 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]]; }
Apple Documentation for Customizing the Appearance:
In iOS version 5.0 and later, you can customize the appearance of tab bars by setting the attributes of the text labels of the elements using the view switches declared by UIBarItem. You can also use the methods listed in the Customizing the Appearance section. You can customize the appearance of all segmented controls using an appearance proxy (for example, [Appearance UITabBarItem]) or just one tab bar. You can also provide ready-made selected and unselected images using the methods listed in the "Managing the finished selected image" section; these methods, however, do not participate in the UIAppearance proxy API (see UIAppearance). UIKit now provides automatic treatment of finished images. For good results, you must provide ready-made selected and unselected images in matching pairs using setFinishedSelectedImage: withFinishedUnselectedImage :.
Edit: Here is another example of using the UIAppearance system and NSDictionary literal syntax:
[[UITabBarItem appearance] setTitleTextAttributes:@{ UITextAttributeFont : [UIFont fontWithName:@"AmericanTypewriter" size:20.0f], UITextAttributeTextColor : [UIColor blackColor], UITextAttributeTextShadowColor : [UIColor grayColor], UITextAttributeTextShadowOffset : [NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)]}];
Edit (by @JeremyWiebe): Starting with iOS 6, dictionary keys have been changed the same way as in OS X:
NSShadow *shadow = [[NSShadow alloc] init]; shadow.shadowColor = [UIColor grayColor]; shadow.shadowOffset = CGSizeMake(0, 1.0); [[UITabBarItem appearance] setTitleTextAttributes:@{ NSFontAttributeName : [UIFont fontWithName:@"AmericanTypewriter" size:20.0f], NSForegroundColorAttributeName : [UIColor blackColor], NSShadowAttributeName : shadow }];
Kjuly Dec 07 '11 at 8:01 2011-12-07 08:01
source share