你是说这个吗?请记住,这仅适用于 iOS5.0 或更高版本。
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 关于自定义外观的文档:
在 iOS v5.0 及更高版本中,您可以通过使用 UIBarItem 声明的外观选择器设置项目标签文本属性来自定义标签栏的外观。您还可以使用“自定义外观”中列出的方法。您可以使用外观代理(例如,[UITabBarItem 外观])自定义所有分段控件的外观,或者仅自定义单个选项卡栏的外观。您还可以使用“管理完成的选定图像”中列出的方法提供完成的选定图像和未选定图像;但是,这些方法不参与 UIAppearance 代理 API(请参阅 UIAppearance)。 UIKit 现在确实为完成的图像提供任何自动处理。为了获得良好的效果,您必须使用 setFinishedSelectedImage:withFinishedUnselectedImage: 成对提供已完成的选定和未选定图像。
编辑:
这是另一个使用 UIAppearance 系统和 NSDictionary 文字语法的示例:
[[UITabBarItem appearance] setTitleTextAttributes:@{
UITextAttributeFont : [UIFont fontWithName:@"AmericanTypewriter" size:20.0f],
UITextAttributeTextColor : [UIColor blackColor],
UITextAttributeTextShadowColor : [UIColor grayColor],
UITextAttributeTextShadowOffset : [NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)]}];
编辑(@JeremyWiebe):
从 iOS 6 开始,字典键已更改为与 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 }];