我正在使用这段代码为我的所有 UIBarButtonItems 设置默认字体(自定义):
NSDictionary *attributesBarButtonItem = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"ProximaNova-Light" size:18.0], NSFontAttributeName, nil];
[[UIBarButtonItem appearance] setTitleTextAttributes:attributesBarButtonItem forState:UIControlStateNormal];
NSLog(@"%@", [[UIBarButtonItem appearance] titleTextAttributesForState:UIControlStateNormal]);
但是,它似乎被忽略了,因为字体没有改变,并且 NSLog 返回(null)。这有点令人困惑,因为它与我用来为所有导航栏设置默认字体的代码几乎相同,而且对它们来说效果很好。
这段代码放置在 AppDelegate 的 didFinishLaunchingWithOptions 中,但我也在其他 viewControllers (viewDidLoad) 中对其进行了测试,结果完全相同。
我注意到的其他奇怪行为:我有一个标签栏控制器,当我加载任何带有栏按钮项目的 viewController 时它不起作用,但是如果我按下另一个 viewController 它可以工作(字体更改为选定的),即使该 viewController 弹出,它也会继续工作,尽管如果按下另一个选项卡,它将停止工作。
任何尝试为 UIBarButtonItems 设置默认字体的帮助将不胜感激。谢谢!