1 /** 2 * 设置导航栏按钮主题 3 */ 4 + (void)setupBarButtonItemTheme 5 { 6 UIBarButtonItem *item = [UIBarButtonItem appearance]; 7 8 // 设置背景 9 if (!iOS7) { 10 [item setBackgroundImage:[UIImage imageWithName:@"navigationbar_button_background"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; 11 [item setBackgroundImage:[UIImage imageWithName:@"navigationbar_button_background_pushed"] forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault]; 12 [item setBackgroundImage:[UIImage imageWithName:@"navigationbar_button_background_disable"] forState:UIControlStateDisabled barMetrics:UIBarMetricsDefault]; 13 } 14 15 // 设置文字属性 16 NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary]; 17 textAttrs[UITextAttributeTextColor] = iOS7 ? [UIColor orangeColor] : [UIColor grayColor]; 18 textAttrs[UITextAttributeTextShadowOffset] = [NSValue valueWithUIOffset:UIOffsetZero]; 19 textAttrs[UITextAttributeFont] = [UIFont systemFontOfSize:iOS7 ? 14 : 12]; 20 [item setTitleTextAttributes:textAttrs forState:UIControlStateNormal]; 21 [item setTitleTextAttributes:textAttrs forState:UIControlStateHighlighted]; 22 } 23 24 /** 25 * 设置导航栏主题 26 */ 27 + (void)setupNavBarTheme 28 { 29 // 取出appearance对象 30 UINavigationBar *navBar = [UINavigationBar appearance]; 31 32 // 设置背景 33 if (!iOS7) { 34 [navBar setBackgroundImage:[UIImage imageWithName:@"navigationbar_background"] forBarMetrics:UIBarMetricsDefault]; 35 [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlackOpaque; 36 } 37 38 // 设置标题属性 39 NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary]; 40 textAttrs[UITextAttributeTextColor] = [UIColor blackColor]; 41 textAttrs[UITextAttributeTextShadowOffset] = [NSValue valueWithUIOffset:UIOffsetZero]; 42 textAttrs[UITextAttributeFont] = [UIFont boldSystemFontOfSize:19]; 43 [navBar setTitleTextAttributes:textAttrs]; 44 }