В iOS7 UIBarButtonItems не учитывают полужирный стиль Done при использовании прокси-сервера UIAppearance.

В iOS7 по умолчанию UIBarButtonItem использует обычный шрифт Helvetica для стиля UIBarButtonItemStylePlain и полужирный шрифт для UIBarButtonItemStyleDone.

В моем приложении используются пользовательские шрифты, и для этого я использую прокси-сервер UIAppearance:

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

Проблема в том, что прокси внешнего вида делает кнопки в стиле Plain and Done шрифтом обычного веса, который я указал выше.

Любые идеи, как я могу заставить UIBarButtonItem использовать разные пользовательские веса шрифта в зависимости от стиля?


person Marc Regan    schedule 24.10.2013    source источник
comment
Эй, Марк, я знаю, что это давно назревший ответ, но вы пытались создать подкласс UIBarButtonItem и добавить собственное представление? Взгляните на этот ответ здесь: stackoverflow.com/questions/18844681/. Надеюсь это поможет :)   -  person Taylor Abernethy Newman    schedule 16.01.2014


Ответы (1)


Я знаю, что это поздний ответ, но это может быть полезно для кого-то:

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

Отредактировано: спасибо за обнаружение моей опечатки :-)

person Neru    schedule 22.01.2014
comment
Спасибо @Neru! Это работает. К вашему сведению: перед строкой шрифта отсутствует символ @. - person Marc Regan; 22.01.2014
comment
Ни мне, ни прокси-серверу внешнего вида не используется... Любой способ сделать это через прокси-сервер внешнего вида? - person Georg; 15.04.2015