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

常用宏定义

时间:2014-09-20 15:59:08      阅读:273      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   os   ar   for   div   sp   

iOS6和iOS7的适配:

#define iOS7 ([[UIDevice currentDevice].systemVersion doubleValue] >= 7.0)
#endif

根据RGB设置一个全局背景色:

//2.获得RGB
#define YLYColor(r,g,b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0];

//3.全局背景色
#define YLYGlobalBg YLYColor(226,226,226);

宏定义NSLog:

// 4.自定义Log
#ifdef DEBUG
#define YLog(...) NSLog(__VA_ARGS__)
#else
#define YLog(...)
#endif

根据色彩地址设置颜色:

//2.添加颜色
#define kUIColorFromRGB(rgbValue) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]

自定义nslog在发布程序时状态改为0或者1即可全部消灭nslog输出信息,很好用:

#define NEED_OUTPUT_LOG                     1

#if NEED_OUTPUT_LOG

#define SLog(xx, ...)   NSLog(xx, ##__VA_ARGS__)
#define SLLog(xx, ...)  NSLog(@"%s(%d): " xx, __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)

#define SLLogRect(rect) \
SLLog(@"%s x=%f, y=%f, w=%f, h=%f", #rect, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height)

#define SLLogPoint(pt) \
SLLog(@"%s x=%f, y=%f", #pt, pt.x, pt.y)

#define SLLogSize(size) \
SLLog(@"%s w=%f, h=%f", #size, size.width, size.height)

#define SLLogColor(_COLOR) \
SLLog(@"%s h=%f, s=%f, v=%f", #_COLOR, _COLOR.hue, _COLOR.saturation, _COLOR.value)

#define SLLogSuperViews(_VIEW) \
{ for (UIView* view = _VIEW; view; view = view.superview) { SLLog(@"%@", view); } }

#define SLLogSubViews(_VIEW) \
{ for (UIView* view in [_VIEW subviews]) { SLLog(@"%@", view); } }

#else

#define SLog(xx, ...)  ((void)0)
#define SLLog(xx, ...)  ((void)0)

#endif

//更改1 为0
#define NEED_OUTPUT_LOG                     1


#if NEED_OUTPUT_LOG


#define SLog(xx, ...)   NSLog(xx, ##__VA_ARGS__)
#define SLLog(xx, ...)  NSLog(@"%s(%d): " xx, __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)


#define SLLogRect(rect) \
SLLog(@"%s x=%f, y=%f, w=%f, h=%f", #rect, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height)


#define SLLogPoint(pt) \
SLLog(@"%s x=%f, y=%f", #pt, pt.x, pt.y)


#define SLLogSize(size) \
SLLog(@"%s w=%f, h=%f", #size, size.width, size.height)


#define SLLogColor(_COLOR) \
SLLog(@"%s h=%f, s=%f, v=%f", #_COLOR, _COLOR.hue, _COLOR.saturation, _COLOR.value)


#define SLLogSuperViews(_VIEW) \
{ for (UIView* view = _VIEW; view; view = view.superview) { SLLog(@"%@", view); } }


#define SLLogSubViews(_VIEW) \
{ for (UIView* view in [_VIEW subviews]) { SLLog(@"%@", view); } }


#else


#define SLog(xx, ...)  ((void)0)
#define SLLog(xx, ...)  ((void)0)


#endif

 

 

常用宏定义

标签:style   blog   color   io   os   ar   for   div   sp   

原文地址:http://www.cnblogs.com/yuanliyong520/p/3983195.html

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