在iOS7中,默认情况下,UIBarButtonItem对样式UIBarButtonItemStylePlain使用Helvetica常规权重字体,对UIBarButtonItemStyleDone使用粗体。
我的应用使用自定义字体,我正在使用UIAppearance代理来实现此目的:
appearance = @{NSFontAttributeName: [UIFont fontWithName:@"ProximaNova-Regular" size:18.0]};
[[UIBarButtonItem appearance] setTitleTextAttributes:appearance
forState:UIControlStateNormal];
问题是,外观代理使普通和完成样式按钮成为我上面指定的常规重量字体。
我有什么想法可以让UIBarButtonItem根据样式使用不同的自定义字体权重?
答案 0 :(得分:3)
我知道这是迟到的回答,但它对某些人有帮助:
UIBarButtonItem *customBarButton =
[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"CustomTitle", @"This button appears in my smexy ViewController's naviagtion bar")
style:UIBarButtonItemStylePlain
target:self
action:@selector(customButtonDidClick:)];
NSDictionary *attributes = @{NSFontAttributeName: [UIFont fontWithName:@"TimesNewRomanPS-BoldMT" size:14.0f],
NSForegroundColorAttributeName: [UIColor redColor]}; // here you can add some other keys (especially in iOS 7) to personalize your button title more
[customBarButton setTitleTextAttributes:attributes forState:UIControlStateNormal];
[self.navigationItem setRightBarButtonItem:customBarButton];
编辑:感谢您发现我的拼写错误: - )