Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In iOS7, UIBarButtonItems do not respect bold "Done" styling when using UIAppearance proxy

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?

like image 787
Marc Regan Avatar asked Oct 24 '13 15:10

Marc Regan


1 Answers

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 :-)

like image 57
Neru Avatar answered Nov 15 '22 06:11

Neru