Mar*_*gan 7 uikit uibarbuttonitem ios uiappearance ios7
在iOS7中,默认情况下,UIBarButtonItem对样式UIBarButtonItemStylePlain使用Helvetica常规权重字体,对UIBarButtonItemStyleDone使用粗体.
我的应用程序使用自定义字体,我使用UIAppearance代理来实现此目的:
appearance = @{NSFontAttributeName: [UIFont fontWithName:@"ProximaNova-Regular" size:18.0]};
[[UIBarButtonItem appearance] setTitleTextAttributes:appearance
forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)
麻烦的是,外观代理使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];
Run Code Online (Sandbox Code Playgroud)
编辑:感谢您发现我的拼写错误:-)
| 归档时间: |
|
| 查看次数: |
2057 次 |
| 最近记录: |