设为首页收藏本站
查看: 921|回复: 0

[业界探讨] ios开发常用的宏

[复制链接]

75

主题

75

帖子

442

积分

网站编辑

Rank: 8Rank: 8

积分
442
发表于 2017-1-17 11:51:25 | 显示全部楼层 |阅读模式
  1. #define NavigationBar_HEIGHT 44

  2. #define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
  3. #define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)
  4. #define SAFE_RELEASE(x) [x release];x=nil
  5. #define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]
  6. #define CurrentSystemVersion ([[UIDevice currentDevice] systemVersion])  
  7. #define CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])

  8. #define BACKGROUND_COLOR [UIColor colorWithRed:242.0/255.0 green:236.0/255.0 blue:231.0/255.0 alpha:1.0]



  9. //use dlog to print while in debug model
  10. #ifdef DEBUG
  11. #   define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
  12. #else
  13. #   define DLog(...)
  14. #endif


  15. #define isRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)
  16. #define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
  17. #define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)


  18. #if TARGET_OS_IPHONE
  19. //iPhone Device
  20. #endif

  21. #if TARGET_IPHONE_SIMULATOR
  22. //iPhone Simulator
  23. #endif


  24. //ARC
  25. #if __has_feature(objc_arc)
  26.     //compiling with ARC
  27. #else
  28.     // compiling without ARC
  29. #endif


  30. //G-C-D
  31. #define BACK(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)
  32. #define MAIN(block) dispatch_async(dispatch_get_main_queue(),block)


  33. #define USER_DEFAULT [NSUserDefaults standardUserDefaults]
  34. #define ImageNamed(_pointer) [UIImage imageNamed:[UIUtil imageName:_pointer]]



  35. #pragma mark - common functions
  36. #define RELEASE_SAFELY(__POINTER) { [__POINTER release]; __POINTER = nil; }


  37. #pragma mark - degrees/radian functions
  38. #define degreesToRadian(x) (M_PI * (x) / 180.0)
  39. #define radianToDegrees(radian) (radian*180.0)/(M_PI)

  40. #pragma mark - color functions
  41. #define RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]
  42. #define RGBACOLOR(r,g,b,a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)]
  43. #define ITTDEBUG
  44. #define ITTLOGLEVEL_INFO     10
  45. #define ITTLOGLEVEL_WARNING  3
  46. #define ITTLOGLEVEL_ERROR    1

  47. #ifndef ITTMAXLOGLEVEL

  48. #ifdef DEBUG
  49.     #define ITTMAXLOGLEVEL ITTLOGLEVEL_INFO
  50. #else
  51.     #define ITTMAXLOGLEVEL ITTLOGLEVEL_ERROR
  52. #endif

  53. #endif

  54. // The general purpose logger. This ignores logging levels.
  55. #ifdef ITTDEBUG
  56.   #define ITTDPRINT(xx, ...)  NSLog(@"%s(%d): " xx, __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
  57. #else
  58.   #define ITTDPRINT(xx, ...)  ((void)0)
  59. #endif

  60. // Prints the current method's name.
  61. #define ITTDPRINTMETHODNAME() ITTDPRINT(@"%s", __PRETTY_FUNCTION__)

  62. // Log-level based logging macros.
  63. #if ITTLOGLEVEL_ERROR <= ITTMAXLOGLEVEL
  64.   #define ITTDERROR(xx, ...)  ITTDPRINT(xx, ##__VA_ARGS__)
  65. #else
  66.   #define ITTDERROR(xx, ...)  ((void)0)
  67. #endif

  68. #if ITTLOGLEVEL_WARNING <= ITTMAXLOGLEVEL
  69.   #define ITTDWARNING(xx, ...)  ITTDPRINT(xx, ##__VA_ARGS__)
  70. #else
  71.   #define ITTDWARNING(xx, ...)  ((void)0)
  72. #endif

  73. #if ITTLOGLEVEL_INFO <= ITTMAXLOGLEVEL
  74.   #define ITTDINFO(xx, ...)  ITTDPRINT(xx, ##__VA_ARGS__)
  75. #else
  76.   #define ITTDINFO(xx, ...)  ((void)0)
  77. #endif

  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. #define ITTAssert(condition, ...)                                       \
  87. do {                                                                      \
  88.     if (!(condition)) {                                                     \
  89.         [[NSAssertionHandler currentHandler]                                  \
  90.             handleFailureInFunction:[NSString stringWithUTF8String:__PRETTY_FUNCTION__] \
  91.                                 file:[NSString stringWithUTF8String:__FILE__]  \
  92.                             lineNumber:__LINE__                                  \
  93.                             description:__VA_ARGS__];                             \
  94.     }                                                                       \
  95. } while(0)



  96. #define _po(o) DLOG(@"%@", (o))
  97. #define _pn(o) DLOG(@"%d", (o))
  98. #define _pf(o) DLOG(@"%f", (o))
  99. #define _ps(o) DLOG(@"CGSize: {%.0f, %.0f}", (o).width, (o).height)
  100. #define _pr(o) DLOG(@"NSRect: {{%.0f, %.0f}, {%.0f, %.0f}}", (o).origin.x, (o).origin.x, (o).size.width, (o).size.height)

  101. #define DOBJ(obj)  DLOG(@"%s: %@", #obj, [(obj) description])

  102. #define MARK    NSLog(@"\nMARK: %s, %d", __PRETTY_FUNCTION__, __LINE__)
复制代码
继续:
  1. #ifndef VIP_One_4_0_BTDefine_h
  2. #define VIP_One_4_0_BTDefine_h


  3. #pragma mark - 设备类型
  4. #define kiPhone4     ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)
  5. #define kiPhone5     ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
  6. #define kiPhone6     ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) : NO)
  7. #define kiPhone6Plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size) : NO)


  8. #pragma mark - 设备信息
  9. #define kIOS_VERSION    [[[UIDevice currentDevice] systemVersion] floatValue]
  10. #define kDEVICE_MODEL   [[UIDevice currentDevice] model]
  11. #define kIS_IPAD        ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
  12. #define kisRetina       ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)
  13. #define kAPP_NAME            [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"]
  14. #define kAPP_VERSION         [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]
  15. #define kAPP_SUB_VERSION     [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]
  16. #define kUDeviceIdentifier   [[UIDevice currentDevice] uniqueDeviceIdentifier]


  17. #pragma mark - 常用宏定义
  18. #define kWS(weakSelf)          __weak __typeof(&*self)weakSelf = self;
  19. #define kSCREEN_WIDTH          ([UIScreen mainScreen].bounds.size.width)
  20. #define kSCREEN_HEIGHT         ([UIScreen mainScreen].bounds.size.height)
  21. #define kUSER_DEFAULT          [NSUserDefaults standardUserDefaults]
  22. #define kNOTIFICATION_DEFAULT  [NSNotificationCenter defaultCenter]
  23. #define kIMAGENAMED(_pointer)  [UIImage imageNamed:[UIUtil imageName:_pointer]]
  24. #define kLOADIMAGE(file,ext)   [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:file ofType:ext]]

  25. #define kScreenWidthScaleSize           (MIN(SCREEN_WIDTH,SCREEN_HEIGHT)/320.0)
  26. #define kScreenWidthScaleSizeByIphone6  (MIN(SCREEN_WIDTH,SCREEN_HEIGHT)/375.0)

  27. #define kDegreesToRadian(x)         (M_PI * (x) / 180.0)
  28. #define kRadianToDegrees(radian)    (radian*180.0)/(M_PI)


  29. #pragma mark - ios版本判断

  30. #define kIOS5_OR_LATER   ( [[[UIDevice currentDevice] systemVersion] compare:@"5.0"] != NSOrderedAscending )
  31. #define kIOS6_OR_LATER   ( [[[UIDevice currentDevice] systemVersion] compare:@"6.0"] != NSOrderedAscending )
  32. #define kIOS7_OR_LATER   ( [[[UIDevice currentDevice] systemVersion] compare:@"7.0"] != NSOrderedAscending )
  33. #define kIOS8_OR_LATER   ( [[[UIDevice currentDevice] systemVersion] compare:@"8.0"] != NSOrderedAscending )


  34. #pragma mark - 是否为空或是[NSNull null]

  35. #define kNotNilAndNull(_ref)  (((_ref) != nil) && (![(_ref) isEqual:[NSNull null]]))
  36. #define kIsNilOrNull(_ref)   (((_ref) == nil) || ([(_ref) isEqual:[NSNull null]]))

  37. #pragma mark - 图片资源获取
  38. #define kIMGFROMBUNDLE( X )     [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:X ofType:@""]]
  39. #define kIMGNAMED( X )         [UIImage imageNamed:X]

  40. #pragma mark - 颜色
  41. #define kCOLOR_RGB(r,g,b)     [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1.0]
  42. #define kCOLOR_RGBA(r,g,b,a)  [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)]


  43. #pragma mark - 定义字号
  44. #define kFONT_TITLE(X)     [UIFont systemFontSize:X]
  45. #define kFONT_CONTENT(X)   [UIFont systemFontSize:X]


  46. #pragma mark - 其他

  47. #define BINDVIEWWIDTH        (ScreenBounds.size.width * 290.0 / 320.0)

  48. #endif
复制代码


回复

使用道具 举报

*滑动验证:
您需要登录后才可以回帖 登录 | 加入社区

本版积分规则

推荐阅读 More>
广告位

Powered by Discuz X3.2

© 2001-2016   

合作伙伴

返回顶部 返回列表