[转载]ios开发常用的宏

收集起来,丢到一个头文件中,这样开发起来就快多啦!

 

  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 //use dlog to print while in debug model
 14 #ifdef DEBUG
 15 #   define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
 16 #else
 17 #   define DLog(...)
 18 #endif
 19  
 20  
 21 #define isRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)
 22 #define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
 23 #define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
 24  
 25  
 26 #if TARGET_OS_IPHONE
 27 //iPhone Device
 28 #endif
 29  
 30 #if TARGET_IPHONE_SIMULATOR
 31 //iPhone Simulator
 32 #endif
 33  
 34  
 35 //ARC
 36 #if __has_feature(objc_arc)
 37     //compiling with ARC
 38 #else
 39     // compiling without ARC
 40 #endif
 41  
 42  
 43 //G-C-D
 44 #define BACK(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)
 45 #define MAIN(block) dispatch_async(dispatch_get_main_queue(),block)
 46  
 47  
 48 #define USER_DEFAULT [NSUserDefaults standardUserDefaults]
 49 #define ImageNamed(_pointer) [UIImage imageNamed:[UIUtil imageName:_pointer]]
 50  
 51  
 52 #pragma mark - common functions 
 53 #define RELEASE_SAFELY(__POINTER) { [__POINTER release]; __POINTER = nil; }
 54  
 55  
 56 #pragma mark - degrees/radian functions 
 57 #define degreesToRadian(x) (M_PI * (x) / 180.0)
 58 #define radianToDegrees(radian) (radian*180.0)/(M_PI)
 59  
 60 #pragma mark - color functions 
 61 #define RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]
 62 #define RGBACOLOR(r,g,b,a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)]
 63 #define ITTDEBUG
 64 #define ITTLOGLEVEL_INFO     10
 65 #define ITTLOGLEVEL_WARNING  3
 66 #define ITTLOGLEVEL_ERROR    1
 67  
 68 #ifndef ITTMAXLOGLEVEL
 69  
 70 #ifdef DEBUG
 71     #define ITTMAXLOGLEVEL ITTLOGLEVEL_INFO
 72 #else
 73     #define ITTMAXLOGLEVEL ITTLOGLEVEL_ERROR
 74 #endif
 75  
 76 #endif
 77  
 78 // The general purpose logger. This ignores logging levels.
 79 #ifdef ITTDEBUG
 80   #define ITTDPRINT(xx, ...)  NSLog(@"%s(%d): " xx, __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
 81 #else
 82   #define ITTDPRINT(xx, ...)  ((void)0)
 83 #endif
 84  
 85 // Prints the current method's name.
 86 #define ITTDPRINTMETHODNAME() ITTDPRINT(@"%s", __PRETTY_FUNCTION__)
 87  
 88 // Log-level based logging macros.
 89 #if ITTLOGLEVEL_ERROR <= ITTMAXLOGLEVEL
 90   #define ITTDERROR(xx, ...)  ITTDPRINT(xx, ##__VA_ARGS__)
 91 #else
 92   #define ITTDERROR(xx, ...)  ((void)0)
 93 #endif
 94  
 95 #if ITTLOGLEVEL_WARNING <= ITTMAXLOGLEVEL
 96   #define ITTDWARNING(xx, ...)  ITTDPRINT(xx, ##__VA_ARGS__)
 97 #else
 98   #define ITTDWARNING(xx, ...)  ((void)0)
 99 #endif
100  
101 #if ITTLOGLEVEL_INFO <= ITTMAXLOGLEVEL
102   #define ITTDINFO(xx, ...)  ITTDPRINT(xx, ##__VA_ARGS__)
103 #else
104   #define ITTDINFO(xx, ...)  ((void)0)
105 #endif
106  
107 #ifdef ITTDEBUG
108   #define ITTDCONDITIONLOG(condition, xx, ...) { if ((condition)) { \
109                                                   ITTDPRINT(xx, ##__VA_ARGS__); \
110                                                 } \
111                                               } ((void)0)
112 #else
113   #define ITTDCONDITIONLOG(condition, xx, ...) ((void)0)
114 #endif
115  
116 #define ITTAssert(condition, ...)                                       \
117 do {                                                                      \
118     if (!(condition)) {                                                     \
119         [[NSAssertionHandler currentHandler]                                  \
120             handleFailureInFunction:[NSString stringWithUTF8String:__PRETTY_FUNCTION__] \
121                                 file:[NSString stringWithUTF8String:__FILE__]  \
122                             lineNumber:__LINE__                                  \
123                             description:__VA_ARGS__];                             \
124     }                                                                       \
125 } while(0)

 

 

 

posted @ 2014-02-03 00:20  yangz405  阅读(161)  评论(0)    收藏  举报