#pragma mark 一个类只会调用一次
+ (void)initialize
{
// 1.取出设置主题的对象
UINavigationBar *navBar = [UINavigationBarappearance];
UIBarButtonItem *barItem = [UIBarButtonItemappearance];
// 2.设置导航栏的背景图片
NSString *navBarBg = nil;
if (iOS7) { // iOS7
navBarBg = @"NavBar64";
// 设置导航栏的渐变色为白色(iOS7中返回箭头的颜色变为这个颜色:白色)
navBar.tintColor = [UIColor whiteColor];
} else { // 非iOS7
navBarBg = @"NavBar";
[UIApplicationsharedApplication].statusBarStyle = UIStatusBarStyleBlackOpaque;
// 设置导航栏按钮的背景图片
[barItem setBackgroundImage:[UIImageimageNamed:@"NavButton"] forState:UIControlStateNormalbarMetrics:UIBarMetricsDefault];
[barItem setBackgroundImage:[UIImageimageNamed:@"NavButtonPressed"] forState:UIControlStateHighlightedbarMetrics:UIBarMetricsDefault];
// 设置导航栏返回按钮的背景图片
[barItem setBackButtonBackgroundImage:[UIImageimageNamed:@"NavBackButton"] forState:UIControlStateNormalbarMetrics:UIBarMetricsDefault];
[barItem setBackButtonBackgroundImage:[UIImageimageNamed:@"NavBackButtonPressed"] forState:UIControlStateHighlightedbarMetrics:UIBarMetricsDefault];
}
[navBar setBackgroundImage:[UIImageimageNamed:navBarBg] forBarMetrics:UIBarMetricsDefault];
// 3.设置导航栏标题颜色为白色
[navBar setTitleTextAttributes:@{
UITextAttributeTextColor : [UIColorwhiteColor]
}];
// 4.设置导航栏按钮文字颜色为白色
[barItem setTitleTextAttributes:@{
UITextAttributeTextColor : [UIColorwhiteColor],
UITextAttributeFont : [UIFontsystemFontOfSize:13]
}forState:UIControlStateNormal];
}
#pragma mark 控制状态栏的样式
/*
状态栏的管理:
1> iOS7之前:UIApplication
2> iOS7开始:交给对应的控制器去管理
*/
- (UIStatusBarStyle)preferredStatusBarStyle
{
// 白色样式
returnUIStatusBarStyleLightContent;
}