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

1

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?

Porterporterage answered 24/10, 2013 at 15:38 Comment(1)
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: #18845181. Hope this helps :)Gman
C
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 :-)

Countermove answered 22/1, 2014 at 13:55 Comment(2)
Thanks @Neru! That works. FYI: There's a missing @ in front of the font string.Porterporterage
Neither to I, it's not using the appearance proxy.... Any way to do it via the appearance proxy?Staphylococcus

© 2022 - 2024 — McMap. All rights reserved.