7

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

My app uses custom fonts, and I'm using a UIAppearance proxy to achieve this:

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

The trouble is, the appearance proxy makes the Plain and Done styled buttons the regular weight font I specified above.

Any ideas how I could get UIBarButtonItem to use different custom font weights depending on the style?

Marc Regan
  • 172
  • 8
  • Hey Mark, I know this is a long overdue answer but did you try subclassing the UIBarButtonItem and adding a custom view? Have a look at this answer here: http://stackoverflow.com/questions/18844681/how-to-make-custom-uibarbuttonitem-with-image-and-label. Hope this helps :) – Taylor Abernethy Newman Jan 15 '14 at 23:43

1 Answers1

3

I know it is late answer, but it can be helpful for somebody:

   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];

Edited: thanks for detection of my typo :-)

Neru
  • 679
  • 6
  • 19