1

Changing the

NSDictionary * barButtonAppearanceDict = @{UITextAttributeFont : font};
    [[UIBarButtonItem appearance] setTitleTextAttributes:barButtonAppearanceDict forState:UIControlStateNormal];

Doesn't affect the UIBarButtonItem when using plain...

How can i change the font for the plain style UIBarButtonItem

This still applies to iOS6

4

2 回答 2

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课堂上实现了这个吗?(例如 indidFinishLaunchingWithOptions方法)

于 2013-10-16T15:13:01.320 回答
0

我在 appdelegate 中设置了以下内容,效果很好:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    [[UIBarButtonItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"Avenir" size:21.0]} forState:UIControlStateNormal];

}
于 2014-03-07T05:39:30.943 回答