In iOS7, UIBarButtonItems do not respect the bold finish style when using the UIAppearance proxy

In iOS7, by default, UIBarButtonItem uses the regular Helvetica weight font for the UIBarButtonItemStylePlain style and bold weight for the UIBarButtonItemStyleDone.

My application uses custom fonts, and for this I use the UIAppearance proxy:

appearance = @{NSFontAttributeName: [UIFont fontWithName:@"ProximaNova-Regular" size:18.0]}; [[UIBarButtonItem appearance] setTitleTextAttributes:appearance forState:UIControlStateNormal]; 

The problem is that the appearance proxy makes regular and ready-made stylized buttons with the usual weight font indicated above.

Any ideas on how I can get a UIBarButtonItem to use different custom fonts depending on the style?

+7
ios uikit ios7 uibarbuttonitem uiappearance
source share
1 answer

I know this is a late answer, but it might be useful for someone:

  UIBarButtonItem *customBarButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"CustomTitle", @"This button appears in my smexy ViewController 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]; 

Edited: thanks for discovering my typo :-)

+3
source share

All Articles