更改
NSDictionary * barButtonAppearanceDict = @{UITextAttributeFont : font};
[[UIBarButtonItem appearance] setTitleTextAttributes:barButtonAppearanceDict forState:UIControlStateNormal];
使用plain ...
时不影响UIBarButtonItem如何更改普通样式UIBarButtonItem的字体
这仍然适用于iOS6
答案 0 :(得分:1)
然而,这适用于我(使用普通的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
- 方法中)
答案 1 :(得分:0)
我在appdelegate中设置了以下内容并且效果很好:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[UIBarButtonItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"Avenir" size:21.0]} forState:UIControlStateNormal];
}