宏的简单应用

http://blog.sina.com.cn/s/blog_4ca9ceef0101isv5.html

http://www.cnblogs.com/zhw511006/archive/2013/03/28/2986355.html

http://blog.sina.com.cn/s/blog_4ca9ceef0101isv5.html

http://my.oschina.net/leejan97/blog/227303

//没用#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 ( @"导航栏标题" );

posted on 2015-11-12 11:43  chengjunde  阅读(187)  评论(0编辑  收藏  举报

导航