http://blog.sina.com.cn/s/blog_4ca9ceef0101isv5.html
//没用#define前是这样的,每个ViewController都要写这么一段重复的代码 写多了就烦了
/***********************处理前*****************************/
UILabel *titleLabel = [[ UILabel alloc ] init ];
titleLabel. backgroundColor = [ UIColor clearColor ];
titleLabel. textColor = [ UIColor redColor ];
titleLabel. text = @"导航栏标题" ;
titleLabel. font =[ UIFont fontWithName : nil size : 17.0f ];
[titleLabel sizeToFit ];
self . navigationItem . titleView = titleLabel;
//在全局配置文件(config.h)中定义了一个宏
#define SET_NAV_TITLE(_TITLE) ({\
UILabel *titleLabel = [[UILabel alloc] init];\
titleLabel.backgroundColor = [UIColor clearColor];\
titleLabel.textColor = [UIColor redColor];\
titleLabel.text = _TITLE;\
titleLabel.font=[UIFont fontWithName:nil size: 17.0f ];\
[titleLabel sizeToFit];\
self.navigationItem.titleView = titleLabel;\
})
//定义了宏后就这么一句了
/***********************处理后*****************************/
SET_NAV_TITLE ( @"导航栏标题" );