更改
NSDictionary * barButtonAppearanceDict = @{UITextAttributeFont : font};
[[UIBarButtonItem appearance] setTitleTextAttributes:barButtonAppearanceDict forState:UIControlStateNormal];
不影响 UIBarButtonItem 使用普通...
如何更改纯样式UIBarButtonItem 的字体
这仍然适用于iOS6
但是,这对我有用(使用普通的BarButtonItem),刚刚对其进行了测试:
[self.myBarButtonItem setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:@"Helvetica" size:22.0],NSFontAttributeName,
nil]forState:UIControlStateNormal];
要使用外观代理,您可以尝试以下操作:
NSDictionary *attrDict = [NSDictionary dictionaryWithObject: [UIFont fontWithName:@"Helvetica" size:22.0] forKey: UITextAttributeFont];
[[UIBarButtonItem appearance] setTitleTextAttributes: attrDict
forState: UIControlStateDisabled];
[[UIBarButtonItem appearance] setTitleTextAttributes: attrDict
forState: UIControlStateNormal];
你确定,你在AppDelegate
类中实现了这一点吗?(例如didFinishLaunchingWithOptions
方法)
我在应用程序委托中设置了以下内容,效果很好:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[UIBarButtonItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"Avenir" size:21.0]} forState:UIControlStateNormal];
}