1.自定義導航控制器
-
2.重寫自定義導航控制器的initialize類方法
- 因為該類在第一次使用導航控制器的使用,正符合,因為主題也只需要設置一次
3.代碼實現
/**
* 當第一次使用這個類的時候會調用一次
*/
+ (void)initialize
{
// 當導航欄用在XMGNavigationController中, appearance設置才會生效
// UINavigationBar *bar = [UINavigationBar appearanceWhenContainedIn:[self class], nil];
UINavigationBar *bar = [UINavigationBar appearance];
[bar setBackgroundImage:[UIImage imageNamed:@"navigationbarBackgroundWhite"] forBarMetrics:UIBarMetricsDefault];
[bar setTitleTextAttributes:@{NSFontAttributeName : [UIFont boldSystemFontOfSize:20]}];
// 設置item
UIBarButtonItem *item = [UIBarButtonItem appearance];
// UIControlStateNormal
NSMutableDictionary *itemAttrs = [NSMutableDictionary dictionary];
itemAttrs[NSForegroundColorAttributeName] = [UIColor blackColor];
itemAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:17];
[item setTitleTextAttributes:itemAttrs forState:UIControlStateNormal];
// UIControlStateDisabled
NSMutableDictionary *itemDisabledAttrs = [NSMutableDictionary dictionary];
itemDisabledAttrs[NSForegroundColorAttributeName] = [UIColor lightGrayColor];
[item setTitleTextAttributes:itemDisabledAttrs forState:UIControlStateDisabled];
}