iOS开发常用的宏

来源:互联网 发布:淘宝情趣女模特都有谁 编辑:程序博客网 时间:2024/05/18 15:52
  1. #define NavigationBar_HEIGHT 44  
  2.    
  3. #define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)  
  4. #define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)  
  5. #define SAFE_RELEASE(x) [x release];x=nil  
  6. #define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]  
  7. #define CurrentSystemVersion ([[UIDevice currentDevice] systemVersion])    
  8. #define CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])   
  9.    
  10. #define BACKGROUND_COLOR [UIColor colorWithRed:242.0/255.0 green:236.0/255.0 blue:231.0/255.0 alpha:1.0]  
  11.    
  12.    
  13.    
  14. //use dlog to print while in debug model  
  15. #ifdef DEBUG  
  16. #   define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);  
  17. #else  
  18. #   define DLog(...)  
  19. #endif  
  20.    
  21.    
  22. #define isRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)  
  23. #define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)  
  24. #define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)  
  25.    
  26.    
  27. #if TARGET_OS_IPHONE  
  28. //iPhone Device  
  29. #endif  
  30.    
  31. #if TARGET_IPHONE_SIMULATOR  
  32. //iPhone Simulator  
  33. #endif  
  34.    
  35.    
  36. //ARC  
  37. #if __has_feature(objc_arc)  
  38.     //compiling with ARC  
  39. #else  
  40.     // compiling without ARC  
  41. #endif  
  42.    
  43.    
  44. //G-C-D  
  45. #define BACK(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)  
  46. #define MAIN(block) dispatch_async(dispatch_get_main_queue(),block)  
  47.    
  48.    
  49. #define USER_DEFAULT [NSUserDefaults standardUserDefaults]  
  50. #define ImageNamed(_pointer) [UIImage imageNamed:[UIUtil imageName:_pointer]]  
  51.    
  52.    
  53.    
  54. #pragma mark - common functions   
  55. #define RELEASE_SAFELY(__POINTER) { [__POINTER release]; __POINTER = nil; }  
  56.    
  57.    
  58. #pragma mark - degrees/radian functions   
  59. #define degreesToRadian(x) (M_PI * (x) / 180.0)  
  60. #define radianToDegrees(radian) (radian*180.0)/(M_PI)  
  61.    
  62. #pragma mark - color functions   
  63. #define RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]  
  64. #define RGBACOLOR(r,g,b,a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)]  
  65. #define ITTDEBUG  
  66. #define ITTLOGLEVEL_INFO     10  
  67. #define ITTLOGLEVEL_WARNING  3  
  68. #define ITTLOGLEVEL_ERROR    1  
  69.    
  70. #ifndef ITTMAXLOGLEVEL  
  71.    
  72. #ifdef DEBUG  
  73.     #define ITTMAXLOGLEVEL ITTLOGLEVEL_INFO  
  74. #else  
  75.     #define ITTMAXLOGLEVEL ITTLOGLEVEL_ERROR  
  76. #endif  
  77.    
  78. #endif  
  79.    
  80. // The general purpose logger. This ignores logging levels.  
  81. #ifdef ITTDEBUG  
  82.   #define ITTDPRINT(xx, ...)  NSLog(@"%s(%d): " xx, __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)  
  83. #else  
  84.   #define ITTDPRINT(xx, ...)  ((void)0)  
  85. #endif  
  86.    
  87. // Prints the current method's name.  
  88. #define ITTDPRINTMETHODNAME() ITTDPRINT(@"%s", __PRETTY_FUNCTION__)  
  89.    
  90. // Log-level based logging macros.  
  91. #if ITTLOGLEVEL_ERROR <= ITTMAXLOGLEVEL  
  92.   #define ITTDERROR(xx, ...)  ITTDPRINT(xx, ##__VA_ARGS__)  
  93. #else  
  94.   #define ITTDERROR(xx, ...)  ((void)0)  
  95. #endif  
  96.    
  97. #if ITTLOGLEVEL_WARNING <= ITTMAXLOGLEVEL  
  98.   #define ITTDWARNING(xx, ...)  ITTDPRINT(xx, ##__VA_ARGS__)  
  99. #else  
  100.   #define ITTDWARNING(xx, ...)  ((void)0)  
  101. #endif  
  102.    
  103. #if ITTLOGLEVEL_INFO <= ITTMAXLOGLEVEL  
  104.   #define ITTDINFO(xx, ...)  ITTDPRINT(xx, ##__VA_ARGS__)  
  105. #else  
  106.   #define ITTDINFO(xx, ...)  ((void)0)  
  107. #endif  
  108.    
  109. #ifdef ITTDEBUG  
  110.   #define ITTDCONDITIONLOG(condition, xx, ...) { if ((condition)) { \  
  111.                                                   ITTDPRINT(xx, ##__VA_ARGS__); \  
  112.                                                 } \  
  113.                                               } ((void)0)  
  114. #else  
  115.   #define ITTDCONDITIONLOG(condition, xx, ...) ((void)0)  
  116. #endif  
  117.    
  118. #define ITTAssert(condition, ...)                                       \  
  119. do {                                                                      \  
  120.     if (!(condition)) {                                                     \  
  121.         [[NSAssertionHandler currentHandler]                                  \  
  122.             handleFailureInFunction:[NSString stringWithUTF8String:__PRETTY_FUNCTION__] \  
  123.                                 file:[NSString stringWithUTF8String:__FILE__]  \  
  124.                             lineNumber:__LINE__                                  \  
  125.                             description:__VA_ARGS__];                             \  
  126.     }                                                                       \  
  127. } while(0)  
  128.    
  129.    
  130.    
  131. #define _po(o) DLOG(@"%@", (o))  
  132. #define _pn(o) DLOG(@"%d", (o))  
  133. #define _pf(o) DLOG(@"%f", (o))  
  134. #define _ps(o) DLOG(@"CGSize: {%.0f, %.0f}", (o).width, (o).height)  
  135. #define _pr(o) DLOG(@"NSRect: {{%.0f, %.0f}, {%.0f, %.0f}}", (o).origin.x, (o).origin.x, (o).size.width, (o).size.height)  
  136.    
  137. #define DOBJ(obj)  DLOG(@"%s: %@", #obj, [(obj) description])  
  138. #define MARK    NSLog(@"\nMARK: %s, %d", __PRETTY_FUNCTION__, __LINE__)  
  139. #define LOADIMAGE(file,ext) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:file ofType:ext]]  
  140. #define VIEWWITHTAG(_OBJECT, _TAG)    [_OBJECT viewWithTag : _TAG]   
  141. #define MyLocal(x, ...) NSLocalizedString(x, nil)  
  142. // rgb颜色转换(16进制->10进制)  
  143. #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]  
  144. #define alertContent(content) \  
  145. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" \  
  146.                                                   message:content \  
  147.                                                   delegate:nil   \  
  148.                                                   cancelButtonTitle:@"确定" \  
  149.                                                   otherButtonTitles:nil];  \  
  150. [alert show];  \  
  151. [alert release];   
  152. #if DEBUG  
  153. #define NSLog(FORMAT, ...) fprintf(stderr,"\nfunction:%s line:%d content:%s\n", __FUNCTION__, __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);  
  154. #else  
  155. #define NSLog(FORMAT, ...) nil  
  156. #endif  
  157.   
  158. //清除背景色  
  159. #define CLEARCOLOR [UIColor clearColor]  
  160.   
  161. //定义UIImage对象  
  162. #define IMAGE(A) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:A ofType:nil]]  
  163.   
  164. //带有RGBA的颜色设置  
  165. #define COLOR(R, G, B, A) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:A]  
  166.   
  167. //方正黑体简体字体定义  
  168. #define FONT(F) [UIFont fontWithName:@"FZHTJW--GB1-0" size:F]  
  169.   
  170. //安全删除对象  
  171. #define SAFE_DELETE(P) if(P) { [P release], P = nil; }  
  172.   
  173. //接口API  
  174. #define APIURL                @"http://xxxxx/"  
  175. //登录  
  176. #define APILogin              [APIURL stringByAppendingString:@"Login"]        //登录API  
0 0
原创粉丝点击