码迷,mamicode.com
首页 > 其他好文 > 详细

宏的简单应用

时间:2015-11-12 13:27:47      阅读:247      评论:0      收藏:0      [点我收藏+]

标签:

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

宏的简单应用

标签:

原文地址:http://www.cnblogs.com/chengjun/p/4958524.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!