在iOS7中,默认情况下,UIBarButtonItem对样式UIBarButtonItemStylePlain使用Helvetica常规权重字体,对UIBarButtonItemStyleDone使用粗体.
我的应用程序使用自定义字体,我使用UIAppearance代理来实现此目的:
appearance = @{NSFontAttributeName: [UIFont fontWithName:@"ProximaNova-Regular" size:18.0]};
[[UIBarButtonItem appearance] setTitleTextAttributes:appearance
forState:UIControlStatenormal];
麻烦的是,外观代理使Plain和Done样式按钮成为我上面指定的常规重量字体.
任何想法如何让UIBarButtonItem根据样式使用不同的自定义字体权重?
解决方法
我知道这是迟到的答案,但它对某些人有帮助:
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];
编辑:感谢您检测我的拼写错误:-)