宏定义

简介: <ol start="1" class="dp-objc" style="padding:0px; border:none; list-style-position:initial; color:rgb(92,92,92); font-family:Consolas,'Courier New',Courier,mono,serif; line-height:26px; margin:0px
  1. // 安全释放  
  2. #define RELEASE_SAFELY(__Pointer) do{[__Pointer release],__Pointer = nil;} while(0)  
  3.   
  4. // 屏幕的物理高度  
  5. #define  ScreenHeight  [UIScreen mainScreen].bounds.size.height  
  6.   
  7. // 屏幕的物理宽度  
  8. #define  ScreenWidth   [UIScreen mainScreen].bounds.size.width  
  9.   
  10. // 调试  
  11. #define NSLOG_FUNCTION NSLog(@"%s,%d",__FUNCTION__,__LINE__)  
  12.   
  13.   
  14.   
  15. //----------------------图片————————————————————————————————————————  
  16.     
  17. //读取本地图片    
  18. #define LOADIMAGE(file,ext) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:file ofType:ext]]    
  19.     
  20. //定义UIImage对象    
  21. #define IMAGE(A) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:A ofType:nil]]    
  22.     
  23. //定义UIImage对象    
  24. #define ImageNamed(_pointer) [UIImage imageNamed:_pointer]   
  25.   
  26.   
  27.   
  28. //———————————————————————颜色类———————————————————————————-----—————————————  
  29. // rgb颜色转换(16进制->10进制)    
  30. #define UIColorFromRGB(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]    
  31.     
  32. //带有RGBA的颜色设置    
  33. #define COLOR(R, G, B, A) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:A]    
  34.     
  35. // 获取RGB颜色    
  36. #define RGBA(r,g,b,a) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]    
  37. #define RGB(r,g,b) RGBA(r,g,b,1.0f)    
  38.     
  39. //背景色    
  40. #define BACKGROUND_COLOR [UIColor colorWithRed:242.0/255.0 green:236.0/255.0 blue:231.0/255.0 alpha:1.0]    
  41.     
  42. //清除背景色    
  43. #define CLEARCOLOR [UIColor clearColor]    
  44.     
  45. #pragma mark - color functions    
  46. #define RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]    
  47. #define RGBACOLOR(r,g,b,a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)]    
  48.   
  49.   
  50.   
  51.   
  52. //———————————————————————TAG宏———————————————————————————-----—————————————  
  53. //viewWithTag  
  54. #define VIEWWITHTAG(_OBJECT, _TAG)    [_OBJECT viewWithTag : _TAG]   
  55.   
  56.   
  57.   
  58.   
  59. //———————————————————————单例模式宏———————————————————————————-----—————————————  
  60.       //.h文件处的声明  
  61. #define DEFINE_SINGLETON_FOR_HEADER(className) \  
  62. \  
  63. + (className *)shared##className;  
  64.   
  65.       //.m文件处的声明  
  66. #define DEFINE_SINGLETON_FOR_CLASS(className) \  
  67. \  
  68. + (className *)shared##className { \  
  69.     static className *shared##className = nil; \  
  70.     static dispatch_once_t onceToken; \  
  71.     dispatch_once(&onceToken, ^{ \  
  72.         shared##className = [[self alloc] init]; \  
  73.     }); \  
  74.     return shared##className; \  
  75. }  
  76.   
  77. //———————————————————————单例模式———————————————————————————-----—————————————  
  78. static DataBaseHandle * handle = nil;  
  79. + (DataBaseHandle *)shareInstance  
  80. {  
  81.     @synchronized(self){  
  82.         if (!handle) {  
  83.             handle = [[DataBaseHandle alloc] init];  
  84.         }  
  85.     }  
  86.     return handle;  
  87. }  
  88.   
  89. —————————————不用你把所有NSLog的删除或注释,直接修改#if 判断的值就行了(1执行,0不执行)——————————————  
  90. #if 1  
  91.   
  92. #define NSLog(FORMAT, ...) fprintf(stderr,"[%s:%d行] %s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);  
  93. #else  
  94.   
  95. #define NSLog(FORMAT, ...) nil  
  96.   
  97. #endif  
  98.   
  99.   
  100. #define NEED_OUTPUT_LOG                     0  
  101. #if NEED_OUTPUT_LOG  
  102.   
  103.     #define SLog(xx, ...)   NSLog(xx, ##__VA_ARGS__)  
  104.     #define SLLog(xx, ...)  NSLog(@"%s(%d): " xx, __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)  
  105.   
  106.     #define SLLogRect(rect) \  
  107.     SLLog(@"%s x=%f, y=%f, w=%f, h=%f", #rect, rect.origin.x, rect.origin.y, \  
  108.     rect.size.width, rect.size.height)  
  109.   
  110.     #define SLLogPoint(pt) \  
  111.     SLLog(@"%s x=%f, y=%f", #pt, pt.x, pt.y)  
  112.   
  113.     #define SLLogSize(size) \  
  114.     SLLog(@"%s w=%f, h=%f", #size, size.width, size.height)  
  115.   
  116.     #define SLLogColor(_COLOR) \  
  117.     SLLog(@"%s h=%f, s=%f, v=%f", #_COLOR, _COLOR.hue, _COLOR.saturation, _COLOR.value)  
  118.   
  119.     #define SLLogSuperViews(_VIEW) \  
  120.     { for (UIView* view = _VIEW; view; view = view.superview) { SLLog(@"%@", view); } }  
  121.   
  122.     #define SLLogSubViews(_VIEW) \  
  123.     { for (UIView* view in [_VIEW subviews]) { SLLog(@"%@", view); } }  
  124.   
  125. #else  
  126.   
  127.     #define SLog(xx, ...)  ((void)0)  
  128.     #define SLLog(xx, ...)  ((void)0)  
  129.   
  130. #endif
目录
相关文章
|
20天前
|
编译器 C语言
【C语言】什么是宏定义?(#define详解)
【C语言】什么是宏定义?(#define详解)
25 0
|
4月前
宏定义和带参数的宏
宏定义和带参数的宏
21 0
|
5月前
|
编译器 C语言
C语言宏定义与条件编译
C语言宏定义与条件编译
|
10月前
|
存储 安全 编译器
【为什么】C++中的宏
【为什么】C++中的宏
|
11月前
|
编译器
宏定义(#define)及相关知识
宏定义(#define)及相关知识
82 0
|
12月前
|
C语言
宏定义#define的使用
宏定义#define的使用
80 0
|
编译器 C语言
常量和宏定义
一、变量 二、常量 三、定义符号常量 四、标识符(identifier) 五、字符串常量
常量和宏定义