iOS常用全局宏


  1. #define LOGOPEN 1  
  2. #define VC_LOGOPEN 1  
  3. #define DB_BLOCK_LOG  
  4. #define NET_BLOCK_LOG 1  
  5.    
  6.    
  7. #pragma mark ---log  flag  
  8.    
  9. #define LogFrame(frame) NSLog(@"frame[X=%.1f,Y=%.1f,W=%.1f,H=%.1f",frame.origin.x,frame.origin.y,frame.size.width,frame.size.height)  
  10. #define LogPoint(point) NSLog(@"Point[X=%.1f,Y=%.1f]",point.x,point.y)  
  11.    
  12. #if LOGOPEN   
  13.     #define DDDLog(FORMAT, ...) fprintf(stderr,"%s:%d\t%s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);  
  14. #else  
  15.     #define DDDLog(FORMAT, ...)  
  16. #endif  
  17.    
  18. //viewController log  
  19. #ifdef VC_LOGOPEN  
  20. #define LogVC DDDLog  
  21. #else  
  22. #define LogVC  
  23. #endif  
  24.    
  25. //dbbase log  
  26. #ifdef DB_BLOCK_LOG  
  27.     #define LogDB DDDLog  
  28. #else  
  29.     #define LogDB  
  30. #endif  
  31.    
  32.    
  33. //networking log  
  34. #if NET_BLOCK_LOG  
  35.     #define LogNET DDDLog  
  36. #else  
  37.     #define LogNET  
  38. #endif  
  39.    
  40. //view log  
  41. #ifdef VIEW_BLOCK_LOG  
  42.     #define LogVIEW DDDLog  
  43. #else  
  44.     #define LogVIEW  
  45. #endif  
  46.    
  47.    
  48. #pragma mark --time setup  
  49.    
  50.    
  51. #if TARGET_IPHONE_SIMULATOR  
  52.     #import <objc/objc-runtime.h>  
  53. #else  
  54.     #import <objc/runtime.h>  
  55. #endif  
  56.    
  57. #ifdef  _DEBUG  
  58.     #define DNSLog(...);    NSLog(__VA_ARGS__);  
  59.     #define DNSLogMethod    NSLog(@"[%s] %@", class_getName([self class]), NSStringFromSelector(_cmd));  
  60.     #define DNSLogPoint(p)  NSLog(@"%f,%f", p.x, p.y);  
  61.     #define DNSLogSize(p)   NSLog(@"%f,%f", p.width, p.height);  
  62.     #define DNSLogRect(p)   NSLog(@"%f,%f %f,%f", p.origin.x, p.origin.y, p.size.width, p.size.height);  
  63.    
  64.     CFAbsoluteTime startTime;  
  65.     #define D_START         startTime=CFAbsoluteTimeGetCurrent();  
  66.     #define D_END           DNSLog(@"[%s] %@ %f seconds", class_getName([self class]), NSStringFromSelector(_cmd), CFAbsoluteTimeGetCurrent() - startTime );  
  67. #else  
  68.     #define DNSLog(...);    // NSLog(__VA_ARGS__);  
  69.     #define DNSLogMethod    // NSLog(@"[%s] %@", class_getName([self class]), NSStringFromSelector(_cmd) );  
  70.     #define DNSLogPoint(p)  // NSLog(@"%f,%f", p.x, p.y);  
  71.     #define DNSLogSize(p)   // NSLog(@"%f,%f", p.width, p.height);  
  72.     #define DNSLogRect(p)   // NSLog(@"%f,%f %f,%f", p.origin.x, p.origin.y, p.size.width, p.size.height);  
  73.    
  74.     #define D_START         // CFAbsoluteTime startTime=CFAbsoluteTimeGetCurrent();  
  75.     #define D_END           // DNSLog(@"New %f seconds", CFAbsoluteTimeGetCurrent() - startTime );  
  76. #endif  
  77.    
  78. #define SAFE_FREE(p) { if(p) { free(p); (p)=NULL; } }  
  79.    
  80. #pragma mark ---- AppDelegate  
  81. //AppDelegate  
  82. #define APPDELEGATE [(AppDelegate*)[UIApplication sharedApplication]  delegate]  
  83. //UIApplication  
  84. #define APPD  [UIApplication sharedApplication]  
  85. #define rootNavVC (UINavigationController*)[[[[UIApplication sharedApplication] delegate] window] rootViewController]  
  86.    
  87. #define isPad  ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)  
  88. #define isiPhone5 ([[UIScreen mainScreen]bounds].size.height == 568)  
  89.    
  90.    
  91.    
  92. #pragma mark ---- String  functions  
  93. #define EMPTY_STRING        @""  
  94. #define STR(key)            NSLocalizedString(key, nil)  
  95.    
  96.    
  97. #pragma mark ---- UIImage  UIImageView  functions  
  98. #define IMG(name) [UIImage imageNamed:name]  
  99. #define IMGF(name) [UIImage imageNamedFixed:name]  
  100.    
  101. #pragma mark ---- File  functions  
  102. #define PATH_OF_APP_HOME    NSHomeDirectory()  
  103. #define PATH_OF_TEMP        NSTemporaryDirectory()  
  104. #define PATH_OF_DOCUMENT    [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]  
  105.    
  106.    
  107. #pragma mark ---- color functions  
  108. #define RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]  
  109. #define RGBACOLOR(r,g,b,a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)]  
  110.    
  111. #pragma mark ----Size ,X,Y, View ,Frame  
  112. //get the  size of the Screen  
  113. #define SCREEN_HEIGHT [[UIScreen mainScreen]bounds].size.height  
  114. #define SCREEN_WIDTH [[UIScreen mainScreen]bounds].size.width  
  115. #define HEIGHT_SCALE  ([[UIScreen mainScreen]bounds].size.height/480.0)  
  116.    
  117. //get the  size of the Application  
  118. #define APP_HEIGHT [[UIScreen mainScreen]applicationFrame].size.height  
  119. #define APP_WIDTH [[UIScreen mainScreen]applicationFrame].size.width  
  120.    
  121. #define APP_SCALE_H  ([[UIScreen mainScreen]applicationFrame].size.height/480.0)  
  122. #define APP_SCALE_W  ([[UIScreen mainScreen]applicationFrame].size.width/320.0)  
  123.    
  124. //get the left top origin's x,y of a view  
  125. #define VIEW_TX(view) (view.frame.origin.x)  
  126. #define VIEW_TY(view) (view.frame.origin.y)  
  127.    
  128. //get the width size of the view:width,height  
  129. #define VIEW_W(view)  (view.frame.size.width)  
  130. #define VIEW_H(view)  (view.frame.size.height)  
  131.    
  132. //get the right bottom origin's x,y of a view  
  133. #define VIEW_BX(view) (view.frame.origin.x + view.frame.size.width)  
  134. #define VIEW_BY(view) (view.frame.origin.y + view.frame.size.height )  
  135.    
  136. //get the x,y of the frame  
  137. #define FRAME_TX(frame)  (frame.origin.x)  
  138. #define FRAME_TY(frame)  (frame.origin.y)  
  139. //get the size of the frame  
  140. #define FRAME_W(frame)  (frame.size.width)  
  141. #define FRAME_H(frame)  (frame.size.height)  
  142.    
  143. #define DistanceFloat(PointA,PointB) sqrtf((PointA.x - PointB.x) * (PointA.x - PointB.x) + (PointA.y - PointB.y) * (PointA.y - PointB.y))  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值