宏定义

//-------------------获取设备大小-------------------------  

  1. //NavBar高度  
  2. #define NavigationBar_HEIGHT 44  
  3. //获取屏幕 宽度、高度  
  4. #define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)  
  5. #define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)  
  6.   
  7. //-------------------获取设备大小-------------------------  
  8.   
  9.   
  10. //-------------------打印日志-------------------------  
  11. //DEBUG  模式下打印日志,当前行  
  12. #ifdef DEBUG  
  13. #   define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);  
  14. #else  
  15. #   define DLog(...)  
  16. #endif  
  17.   
  18.   
  19. //重写NSLog,Debug模式下打印日志和当前行数  
  20. #if DEBUG  
  21. #define NSLog(FORMAT, ...) fprintf(stderr,"\nfunction:%s line:%d content:%s\n", __FUNCTION__, __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);  
  22. #else  
  23. #define NSLog(FORMAT, ...) nil  
  24. #endif  
  25.   
  26. //DEBUG  模式下打印日志,当前行 并弹出一个警告  
  27. #ifdef DEBUG  
  28. #   define ULog(fmt, ...)  { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"%s\n [Line %d] ", __PRETTY_FUNCTION__, __LINE__] message:[NSString stringWithFormat:fmt, ##__VA_ARGS__]  delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [alert show]; }  
  29. #else  
  30. #   define ULog(...)  
  31. #endif  
  32.   
  33.   
  34. #define ITTDEBUG  
  35. #define ITTLOGLEVEL_INFO     10  
  36. #define ITTLOGLEVEL_WARNING  3  
  37. #define ITTLOGLEVEL_ERROR    1  
  38.   
  39. #ifndef ITTMAXLOGLEVEL  
  40.   
  41. #ifdef DEBUG  
  42. #define ITTMAXLOGLEVEL ITTLOGLEVEL_INFO  
  43. #else  
  44. #define ITTMAXLOGLEVEL ITTLOGLEVEL_ERROR  
  45. #endif  
  46.   
  47. #endif  
  48.   
  49. // The general purpose logger. This ignores logging levels.  
  50. #ifdef ITTDEBUG  
  51. #define ITTDPRINT(xx, ...)  NSLog(@"%s(%d): " xx, __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)  
  52. #else  
  53. #define ITTDPRINT(xx, ...)  ((void)0)  
  54. #endif  
  55.   
  56. // Prints the current method's name.  
  57. #define ITTDPRINTMETHODNAME() ITTDPRINT(@"%s", __PRETTY_FUNCTION__)  
  58.   
  59. // Log-level based logging macros.  
  60. #if ITTLOGLEVEL_ERROR <= ITTMAXLOGLEVEL  
  61. #define ITTDERROR(xx, ...)  ITTDPRINT(xx, ##__VA_ARGS__)  
  62. #else  
  63. #define ITTDERROR(xx, ...)  ((void)0)  
  64. #endif  
  65.   
  66. #if ITTLOGLEVEL_WARNING <= ITTMAXLOGLEVEL  
  67. #define ITTDWARNING(xx, ...)  ITTDPRINT(xx, ##__VA_ARGS__)  
  68. #else  
  69. #define ITTDWARNING(xx, ...)  ((void)0)  
  70. #endif  
  71.   
  72. #if ITTLOGLEVEL_INFO <= ITTMAXLOGLEVEL  
  73. #define ITTDINFO(xx, ...)  ITTDPRINT(xx, ##__VA_ARGS__)  
  74. #else  
  75. #define ITTDINFO(xx, ...)  ((void)0)  
  76. #endif  
  77.   
  78. #ifdef ITTDEBUG  
  79. #define ITTDCONDITIONLOG(condition, xx, ...) { if ((condition)) { \  
  80. ITTDPRINT(xx, ##__VA_ARGS__); \  
  81. } \  
  82. } ((void)0)  
  83. #else  
  84. #define ITTDCONDITIONLOG(condition, xx, ...) ((void)0)  
  85. #endif  
  86.   
  87. #define ITTAssert(condition, ...)                                       \  
  88. do {                                                                      \  
  89. if (!(condition)) {                                                     \  
  90. [[NSAssertionHandler currentHandler]                                  \  
  91. handleFailureInFunction:[NSString stringWithUTF8String:__PRETTY_FUNCTION__] \  
  92. file:[NSString stringWithUTF8String:__FILE__]  \  
  93. lineNumber:__LINE__                                  \  
  94. description:__VA_ARGS__];                             \  
  95. }                                                                       \  
  96. while(0)  
  97.   
  98. //---------------------打印日志--------------------------  
  99.   
  100.   
  101. //----------------------系统----------------------------  
  102.   
  103. //获取系统版本  
  104. #define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]  
  105. #define CurrentSystemVersion [[UIDevice currentDevice] systemVersion]  
  106.   
  107. //获取当前语言  
  108. #define CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])  
  109.   
  110. //判断是否 Retina屏、设备是否%fhone 5、是否是iPad  
  111. #define isRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)  
  112. #define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)  
  113. #define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)  
  114.   
  115.   
  116. //判断是真机还是模拟器  
  117. #if TARGET_OS_IPHONE  
  118. //iPhone Device  
  119. #endif  
  120.   
  121. #if TARGET_IPHONE_SIMULATOR  
  122. //iPhone Simulator  
  123. #endif  
  124.   
  125. //检查系统版本  
  126. #define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)  
  127. #define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)  
  128. #define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)  
  129. #define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)  
  130. #define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)  
  131.   
  132.   
  133. //----------------------系统----------------------------  
  134.   
  135.   
  136. //----------------------内存----------------------------  
  137.   
  138. //使用ARC和不使用ARC  
  139. #if __has_feature(objc_arc)  
  140. //compiling with ARC  
  141. #else  
  142. // compiling without ARC  
  143. #endif  
  144.   
  145. #pragma mark - common functions  
  146. #define RELEASE_SAFELY(__POINTER) { [__POINTER release]; __POINTER = nil; }  
  147.   
  148. //释放一个对象  
  149. #define SAFE_DELETE(P) if(P) { [P release], P = nil; }  
  150.   
  151. #define SAFE_RELEASE(x) [x release];x=nil  
  152.   
  153.   
  154.   
  155. //----------------------内存----------------------------  
  156.   
  157.   
  158. //----------------------图片----------------------------  
  159.   
  160. //读取本地图片  
  161. #define LOADIMAGE(file,ext) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:file ofType:ext]]  
  162.   
  163. //定义UIImage对象  
  164. #define IMAGE(A) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:A ofType:nil]]  
  165.   
  166. //定义UIImage对象  
  167. #define ImageNamed(_pointer) [UIImage imageNamed:[UIUtil imageName:_pointer]]  
  168.   
  169. //建议使用前两种宏定义,性能高于后者  
  170. //----------------------图片----------------------------  
  171.   
  172.   
  173.   
  174. //----------------------颜色类---------------------------  
  175. // rgb颜色转换(16进制->10进制)  
  176. #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]  
  177.   
  178. //带有RGBA的颜色设置  
  179. #define COLOR(R, G, B, A) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:A]  
  180.   
  181. // 获取RGB颜色  
  182. #define RGBA(r,g,b,a) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]  
  183. #define RGB(r,g,b) RGBA(r,g,b,1.0f)  
  184.   
  185. //背景色  
  186. #define BACKGROUND_COLOR [UIColor colorWithRed:242.0/255.0 green:236.0/255.0 blue:231.0/255.0 alpha:1.0]  
  187.   
  188. //清除背景色  
  189. #define CLEARCOLOR [UIColor clearColor]  
  190.   
  191. #pragma mark - color functions  
  192. #define RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]  
  193. #define RGBACOLOR(r,g,b,a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)]  
  194.   
  195. //----------------------颜色类--------------------------  
  196.   
  197.   
  198.   
  199. //----------------------其他----------------------------  
  200.   
  201. //方正黑体简体字体定义  
  202. #define FONT(F) [UIFont fontWithName:@"FZHTJW--GB1-0" size:F]  
  203.   
  204.   
  205. //定义一个API  
  206. #define APIURL                @"http://xxxxx/"  
  207. //登陆API  
  208. #define APILogin              [APIURL stringByAppendingString:@"Login"]  
  209.   
  210. //设置View的tag属性  
  211. #define VIEWWITHTAG(_OBJECT, _TAG)    [_OBJECT viewWithTag : _TAG]  
  212. //程序的本地化,引用国际化的文件  
  213. #define MyLocal(x, ...) NSLocalizedString(x, nil)  
  214.   
  215. //G-C-D  
  216. #define BACK(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)  
  217. #define MAIN(block) dispatch_async(dispatch_get_main_queue(),block)  
  218.   
  219. //NSUserDefaults 实例化  
  220. #define USER_DEFAULT [NSUserDefaults standardUserDefaults]  
  221.   
  222.   
  223. //由角度获取弧度 有弧度获取角度  
  224. #define degreesToRadian(x) (M_PI * (x) / 180.0)  
  225. #define radianToDegrees(radian) (radian*180.0)/(M_PI)  
  226.   
  227.   
  228.   
  229. //单例化一个类  
  230. #define SYNTHESIZE_SINGLETON_FOR_CLASS(classname) \  
  231. \  
  232. static classname *shared##classname = nil; \  
  233. \  
  234. + (classname *)shared##classname \  
  235. { \  
  236. @synchronized(self) \  
  237. { \  
  238. if (shared##classname == nil) \  
  239. { \  
  240. shared##classname = [[self alloc] init]; \  
  241. } \  
  242. } \  
  243. \  
  244. return shared##classname; \  
  245. } \  
  246. \  
  247. + (id)allocWithZone:(NSZone *)zone \  
  248. { \  
  249. @synchronized(self) \  
  250. { \  
  251. if (shared##classname == nil) \  
  252. { \  
  253. shared##classname = [super allocWithZone:zone]; \  
  254. return shared##classname; \  
  255. } \  
  256. } \  
  257. \  
  258. return nil; \  
  259. } \  
  260. \  
  261. - (id)copyWithZone:(NSZone *)zone \  
  262. { \  
  263. return self; \  
  264. }  
  265.   
  266.   
  267.   
  268. #endif  

 

posted @ 2013-06-13 11:06  leevaboo  Views(242)  Comments(0Edit  收藏  举报