新浪微博客户端(4)-设置导航栏主题

为了使整个项目的NavigationBar 上的UIBarButtonItem的颜色,字体大小一致,需要设置导航栏主题。

由于项目使用的是自定义的DJNavigationController,而又要保证只设置一次,所以将设置主题的代码写在DJNavigationController.m文件中的initialize方法中。

DJNavigationController.m

#import "DJNavigationController.h"

@implementation DJNavigationController



+ (void)initialize {

    UIBarButtonItem *btnItem = [UIBarButtonItem appearance];
    
    // 设置当前item可用状态
    NSMutableDictionary *normalAttr = [NSMutableDictionary dictionary];
    // 设置前景色
    normalAttr[NSForegroundColorAttributeName] = [UIColor orangeColor];
    // 设置当前字体大小
    normalAttr[NSFontAttributeName] = [UIFont systemFontOfSize:14];
    [btnItem setTitleTextAttributes:normalAttr forState:UIControlStateNormal];
    
    
    // 设置当前item不可用状态
    NSMutableDictionary *disableAttr = [NSMutableDictionary dictionary];
    disableAttr[NSForegroundColorAttributeName] = [UIColor grayColor];
    disableAttr[NSFontAttributeName] = [UIFont systemFontOfSize:14];
    [btnItem setTitleTextAttributes:disableAttr forState:UIControlStateDisabled];
    
}

 

最终效果:

 

posted @ 2016-10-14 21:14  夜行过客  阅读(953)  评论(0编辑  收藏  举报