Подтвердить что ты не робот

Изменить шрифт обратной кнопки на uinavigationcontroller

Я пытаюсь изменить цвет шрифта текста на моей обратной кнопке в моем UINavigationControllerBar

    [[UIBarButtonItem appearance] setTitleColor:[UIColor redColor] forState:UIControlStateNormal];

дает мне эту ошибку: [_UIBarItemAppearance setTitleColor: forState:]: непризнанный селектор, отправленный в экземпляр 0x69aeb70 '

Любая помощь? Спасибо!

4b9b3361

Ответ 1

Используйте вместо этого функцию по умолчанию, доступную в ios 5

UIBarButtonItem *backbutton =  [[UIBarButtonItem alloc] initWithTitle:@"back" style:UIBarButtonItemStyleBordered target:nil action:nil];    

    [backbutton setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                   [UIColor blackColor],UITextAttributeTextColor,[UIFont fontWithName:TEXTFONT size:16.0f],UITextAttributeFont,
                                                   nil] forState:UIControlStateNormal]; 

Ответ 2

NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
[attributes setValue:[UIColor colorWithRed:(163.0f/255.0f) green:(0.0f) blue:(0.0f) alpha:1.0f] forKey:UITextAttributeTextColor];
[attributes setValue:[UIColor clearColor] forKey:UITextAttributeTextShadowColor];
[attributes setValue:[NSValue valueWithUIOffset:UIOffsetMake(0.0, 0.0)] forKey:UITextAttributeTextShadowOffset];
[[UIBarButtonItem appearance] setTitleTextAttributes:attributes forState:UIControlStateNormal];

похоже, работает!

Ответ 3

[[UIBarButtonItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                     [UIFont fontWithName:kDefaultFont size:16.0f],UITextAttributeFont,
                                                     nil] forState:UIControlStateNormal];

Ответ 4

И прекрасное решение iOS7 + (из-за имен атрибутов):

NSShadow *shadow = [NSShadow new];
[shadow setShadowColor: [UIColor colorWithWhite:0.0f alpha:0.750f]];
[shadow setShadowOffset: CGSizeMake(0.0f, 1.0f)];

[[UIBarButtonItem appearance] setTitleTextAttributes:@{
        NSFontAttributeName: [UIFont systemFontOfSize:24],
        NSForegroundColorAttributeName: [UIColor colorWithWhite:0.2 alpha:1.0],
        NSShadowAttributeName: shadow,
} forState:UIControlStateNormal];