2015-08-05 3 views
0

У меня есть панель навигации на viewController, которую я могу включить/отключить. Проблема заключается в том, что я не могу получить шрифт для UIBarButtonItem s для изменения цвета после того, как изначально загружается представление, хотя стрелка назад изменится.UINavigationBar назад кнопка цвет элемента шрифта не будет установлен

Я отключить UINavigationBar на myViewController с помощью следующей строки кода:

self.navigationController.navigationBar.userInteractionEnabled = NO; 

Я UIControlState с сконфигурированной в AppDelegate.m для UIBarButtonItem с для включен и выключен, но ничего не происходит шрифту после представление первоначально загружается.

В моей AppDelegate.m, у меня есть следующий код, чтобы установить шрифт и цвет UINavigationBar «s:

// UIBarButtonItem styling 
NSShadow *shadow = [[NSShadow alloc]init]; 
shadow.shadowOffset = CGSizeMake(0.0, 1.0); 
shadow.shadowColor = [UIColor whiteColor]; 

// enabled 
NSDictionary *enabledTextAttributeDictionary = @{NSForegroundColorAttributeName : [UIColor customCellHyperlinkColor], NSShadowAttributeName: shadow, NSFontAttributeName:[UIFont fontWithName:@"GillSans" size:17.0]}; 

[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleTextAttributes:enabledTextAttributeDictionary forState:UIControlStateNormal]; 

// disabled 
NSDictionary *disabledTextAttributeDictionary = @{NSForegroundColorAttributeName : [UIColor lightGrayColor], NSShadowAttributeName: shadow, NSFontAttributeName:[UIFont fontWithName:@"GillSans" size:17.0]}; 

[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleTextAttributes:disabledTextAttributeDictionary forState:UIControlStateDisabled]; 

// UINavigationBarTitle styling 
NSDictionary *titleAttributeDictionary = @{NSForegroundColorAttributeName : [UIColor blackColor], NSShadowAttributeName: shadow, NSFontAttributeName:[UIFont fontWithName:@"GillSans" size:19.0]}; 

[[UINavigationBar appearanceWhenContainedIn:[UINavigationController class], nil]setTitleTextAttributes:titleAttributeDictionary]; 

Я думал, так как я настроил 2 состояния (UIControlStateNormal/UIControlStateDisabled) в AppDelegate.m, ничто не должно быть кроме включения/выключения navigationBar. Включение/отключение действительно включает/отключает, но цвет на ярлыке кнопки возврата не изменяется (хотя вначале он был установлен на цвет, который я установил для UIControlStateNormal в AppDelegate).

Я попытался установить его вручную, но ярлык на backButtonItem остается синим, а значок слева от него - светло-серый. Что (очевидная вещь) я упускаю, что мешает мне изменить цвет шрифта моей кнопки?

+0

self.navigationController.navigationItem.leftBarButtonItem.tintColor = = [UIColor lightGrayColor]; –

+0

Спасибо. Значки стрелок, но цвет шрифта для ярлыка кнопки «Назад» отсутствует. – Adrian

ответ

0

Я думаю, вам нужно использовать

[self.navigationController.navigationBar setBarTintColor:[UIColor lightGrayColor]]; 
self.navigationController.navigationBar.tintColor = [UIColor lightGrayColor]; 
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor lightGrayColor], NSFontAttributeName : place your font here}]; 

вместо

self.navigationController.navigationBar.tintColor = [UIColor lightGrayColor]; 
+0

Я не верю, что это правильная линия. Спасибо за ваш вклад. – Adrian

0

Я думаю, что вы ищете для этого Добавьте этот код в вас AppDelegate.m

NSShadow *shadow = [[NSShadow alloc] init]; 
shadow.shadowOffset = CGSizeMake(0.0, 1.0); 
shadow.shadowColor = [UIColor clearColor]; 

[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] 
setTitleTextAttributes: 
@{NSForegroundColorAttributeName:[UIColor redColor], 
    NSShadowAttributeName:shadow, 
    NSFontAttributeName:[UIFont systemFontOfSize:13.0] 
    } 
forState:UIControlStateNormal]; 
+0

Спасибо. Меня беспокоит вопрос: 'UIControlStateDisabled'. – Adrian

Смежные вопросы