LRMacroDefinitionHeader.h 7.1 KB

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