LRMacroDefinitionHeader.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. //
  2. // LRMacroDefinitionHeader.h
  3. // LivenessDetector
  4. //
  5. // Created by Xiaoyang Lin on 16/10/11.
  6. // Copyright © 2016年 Oliveapp. All rights reserved.
  7. //
  8. #ifndef LRMacroDefinitionHeader_h
  9. #define LRMacroDefinitionHeader_h
  10. //2.获取通知中心
  11. #define LRNotificationCenter [NSNotificationCenter defaultCenter]
  12. //3.设置随机颜色
  13. #define LRRandomColor [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1.0]
  14. //4.设置RGB颜色/设置RGBA颜色
  15. #define LRRGBColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
  16. #define LRRGBAColor(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(r)/255.0 blue:(r)/255.0 alpha:a]
  17. // clear背景颜色
  18. #define LRClearColor [UIColor clearColor]
  19. //5.自定义高效率的 NSLog
  20. #ifdef DEBUG
  21. #define LRLog(...) NSLog(@"%s 第%d行 \n %@\n\n",__func__,__LINE__,[NSString stringWithFormat:__VA_ARGS__])
  22. #else
  23. #define LRLog(...)
  24. #endif
  25. //6.弱引用/强引用
  26. #define LRWeakSelf(type) __weak typeof(type) weak##type = type;
  27. #define LRStrongSelf(type) __strong typeof(type) type = weak##type;
  28. //7.设置 view 圆角和边框
  29. #define LRViewBorderRadius(View, Radius, Width, Color)\
  30. \
  31. [View.layer setCornerRadius:(Radius)];\
  32. [View.layer setMasksToBounds:YES];\
  33. [View.layer setBorderWidth:(Width)];\
  34. [View.layer setBorderColor:[Color CGColor]]
  35. //8.由角度转换弧度 由弧度转换角度
  36. #define LRDegreesToRadian(x) (M_PI * (x) / 180.0)
  37. #define LRRadianToDegrees(radian) (radian*180.0)/(M_PI)
  38. //9.设置加载提示框(第三方框架:Toast)
  39. #define LRToast(str) CSToastStyle *style = [[CSToastStyle alloc] initWithDefaultStyle]; \
  40. [kWindow makeToast:str duration:0.6 position:CSToastPositionCenter style:style];\
  41. kWindow.userInteractionEnabled = NO; \
  42. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.6 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{\
  43. kWindow.userInteractionEnabled = YES;\
  44. });\
  45. //10.设置加载提示框(第三方框架:MBProgressHUD)
  46. // 加载
  47. #define kShowNetworkActivityIndicator() [UIApplication sharedApplication].networkActivityIndicatorVisible = YES
  48. // 收起加载
  49. #define HideNetworkActivityIndicator() [UIApplication sharedApplication].networkActivityIndicatorVisible = NO
  50. // 设置加载
  51. #define NetworkActivityIndicatorVisible(x) [UIApplication sharedApplication].networkActivityIndicatorVisible = x
  52. #define kWindow [UIApplication sharedApplication].keyWindow
  53. #define kBackView for (UIView *item in kWindow.subviews) { \
  54. if(item.tag == 10000) \
  55. { \
  56. [item removeFromSuperview]; \
  57. UIView * aView = [[UIView alloc] init]; \
  58. aView.frame = [UIScreen mainScreen].bounds; \
  59. aView.tag = 10000; \
  60. aView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3]; \
  61. [kWindow addSubview:aView]; \
  62. } \
  63. } \
  64. #define kShowHUDAndActivity kBackView;[MBProgressHUD showHUDAddedTo:kWindow animated:YES];kShowNetworkActivityIndicator()
  65. #define kHiddenHUD [MBProgressHUD hideAllHUDsForView:kWindow animated:YES]
  66. #define kRemoveBackView for (UIView *item in kWindow.subviews) { \
  67. if(item.tag == 10000) \
  68. { \
  69. [UIView animateWithDuration:0.4 animations:^{ \
  70. item.alpha = 0.0; \
  71. } completion:^(BOOL finished) { \
  72. [item removeFromSuperview]; \
  73. }]; \
  74. } \
  75. } \
  76. #define kHiddenHUDAndAvtivity kRemoveBackView;kHiddenHUD;HideNetworkActivityIndicator()
  77. //11.获取view的frame/图片资源
  78. //获取view的frame(不建议使用)
  79. //#define kGetViewWidth(view) view.frame.size.width
  80. //#define kGetViewHeight(view) view.frame.size.height
  81. //#define kGetViewX(view) view.frame.origin.x
  82. //#define kGetViewY(view) view.frame.origin.y
  83. //获取图片资源
  84. #define kGetImage(imageName) [UIImage imageNamed:[NSString stringWithFormat:@"%@",imageName]]
  85. //12.获取当前语言
  86. #define LRCurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])
  87. //13.使用 ARC 和 MRC
  88. #if __has_feature(objc_arc)
  89. // ARC
  90. #else
  91. // MRC
  92. #endif
  93. //14.判断当前的iPhone设备/系统版本
  94. //判断是否为iPhone
  95. #define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
  96. //判断是否为iPad
  97. #define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  98. //判断是否为ipod
  99. #define IS_IPOD ([[[UIDevice currentDevice] model] isEqualToString:@"iPod touch"])
  100. // 判断是否为 iPhone 5SE
  101. #define iPhone5SE [[UIScreen mainScreen] bounds].size.width == 320.0f && [[UIScreen mainScreen] bounds].size.height == 568.0f
  102. // 判断是否为iPhone 6/6s
  103. #define iPhone6_6s [[UIScreen mainScreen] bounds].size.width == 375.0f && [[UIScreen mainScreen] bounds].size.height == 667.0f
  104. // 判断是否为iPhone 6Plus/6sPlus
  105. #define iPhone6Plus_6sPlus [[UIScreen mainScreen] bounds].size.width == 414.0f && [[UIScreen mainScreen] bounds].size.height == 736.0f
  106. //获取系统版本
  107. #define IOS_SYSTEM_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]
  108. //判断 iOS 8 或更高的系统版本
  109. #define IOS_VERSION_8_OR_LATER (([[[UIDevice currentDevice] systemVersion] floatValue] >=8.0)? (YES):(NO))
  110. //15.判断是真机还是模拟器
  111. #if TARGET_OS_IPHONE
  112. //iPhone Device
  113. #endif
  114. #if TARGET_IPHONE_SIMULATOR
  115. //iPhone Simulator
  116. #endif
  117. //16.沙盒目录文件
  118. //获取temp
  119. #define kPathTemp NSTemporaryDirectory()
  120. //获取沙盒 Document
  121. #define kPathDocument [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]
  122. //获取沙盒 Cache
  123. #define kPathCache [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]
  124. //17.GCD 的宏定义
  125. //GCD - 一次性执行
  126. #define kDISPATCH_ONCE_BLOCK(onceBlock) static dispatch_once_t onceToken; dispatch_once(&onceToken, onceBlock);
  127. //GCD - 在Main线程上运行
  128. #define kDISPATCH_MAIN_THREAD(mainQueueBlock) dispatch_async(dispatch_get_main_queue(), mainQueueBlock);
  129. //GCD - 开启异步线程
  130. #define kDISPATCH_GLOBAL_QUEUE_DEFAULT(globalQueueBlock) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), globalQueueBlocl);
  131. #endif /* LRMacroDefinitionHeader_h */