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