BaseMaroDefine.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. //
  2. // BaseMaroDefine.h
  3. // KSToolsModule
  4. //
  5. // Created by 王智 on 2024/1/15.
  6. //
  7. #ifndef BaseMaroDefine_h
  8. #define BaseMaroDefine_h
  9. #define BLOCK_EXEC(block, ...) !block ?: block(__VA_ARGS__);
  10. #pragma mark ------ 宽高相关
  11. #define kScreenWidth [UIScreen mainScreen].bounds.size.width
  12. #define kScreenHeight [UIScreen mainScreen].bounds.size.height
  13. #define KLandscapeWidth ([UIScreen mainScreen].bounds.size.width > [UIScreen mainScreen].bounds.size.height ? [UIScreen mainScreen].bounds.size.width : [UIScreen mainScreen].bounds.size.height)
  14. #define KLandscapeHeight ([UIScreen mainScreen].bounds.size.width > [UIScreen mainScreen].bounds.size.height ? [UIScreen mainScreen].bounds.size.height : [UIScreen mainScreen].bounds.size.width)
  15. #define KPortraitWidth ([UIScreen mainScreen].bounds.size.width > [UIScreen mainScreen].bounds.size.height ? [UIScreen mainScreen].bounds.size.height : [UIScreen mainScreen].bounds.size.width)
  16. #define KPortraitHeight ([UIScreen mainScreen].bounds.size.width > [UIScreen mainScreen].bounds.size.height ? [UIScreen mainScreen].bounds.size.width : [UIScreen mainScreen].bounds.size.height)
  17. #define kTabBarHeight (IS_iPhoneX ? 83 : 49)
  18. #define kNaviBarHeight (IS_iPhoneX ? 88.0 : 64.0)
  19. //iPhoneX机型判断
  20. #define IS_iPhoneX ({\
  21. BOOL iPhoneXSeries = NO;\
  22. if (UIDevice.currentDevice.userInterfaceIdiom != UIUserInterfaceIdiomPhone) {\
  23. iPhoneXSeries = NO;\
  24. }\
  25. else if (@available(iOS 11.0, *)) {\
  26. UIWindow *mainWindow = [[[UIApplication sharedApplication] delegate] window];\
  27. if (mainWindow.safeAreaInsets.bottom > 0.0) {\
  28. iPhoneXSeries = YES;\
  29. }\
  30. }\
  31. (iPhoneXSeries);\
  32. })
  33. //状态栏高度配置
  34. #define STATUS_GAP (IS_iPhoneX? 44 : 20)
  35. //设备底部安全距离配置
  36. #define iPhoneXSafeBottomMargin (IS_iPhoneX ? 34.f : 0.f)
  37. #define iPhoneXSafeTopMargin ((IS_iPhoneX ? 24.f : 0.f))
  38. #pragma mark ------ 字体比例和宽高比例 (暂时可能不需要使用)
  39. /**宽度比例*/
  40. #define KS_ScaleWidth(__VA_ARGS__) ([UIScreen mainScreen].bounds.size.width/375)*(__VA_ARGS__)
  41. /**高度比例*/
  42. #define KS_ScaleHeight(__VA_ARGS__) ([UIScreen mainScreen].bounds.size.height/667)*(__VA_ARGS__)
  43. /**全局字体*/
  44. #define GlobelNormalFont(__VA_ARGS__) ([UIFont systemFontOfSize:KS_ScaleFont(__VA_ARGS__)])
  45. /**字体比例*/
  46. #define KS_ScaleFont(__VA_ARGS__) ([UIScreen mainScreen].bounds.size.width/375)*(__VA_ARGS__)
  47. #pragma mark----- 颜色
  48. #define HexRGB(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]
  49. #define HexRGBAlpha(rgbValue,a) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:(a)]
  50. // 延时调用宏
  51. #define dispatch_delay_block(when,time,block)\
  52. dispatch_time_t delayTime = dispatch_time(when, time);\
  53. dispatch_after(delayTime, dispatch_get_main_queue(),block);
  54. /*---------------------------------------- 常见固态宏 ---------------------------------------
  55. */
  56. #define USER_DEFAULT [NSUserDefaults standardUserDefaults]
  57. #define FILE_MANAGER [NSFileManager defaultManager]
  58. #define NOTIFICATION_CENTER [NSNotificationCenter defaultCenter]
  59. #define SET_IMAGE(ImageName) [UIImage imageNamed:ImageName]
  60. #define SET_WORD_SIZE(size) [UIFont systemFontOfSize:size]
  61. #define SET_BOLD_WORD_SIZE(size) [UIFont boldSystemFontOfSize:size]
  62. #define UserDefault(_key_) [[NSUserDefaults standardUserDefaults] objectForKey:_key_]
  63. #define UserDefaultSet(_value_,_key_) ([[NSUserDefaults standardUserDefaults] setValue:_value_ forKey:_key_])
  64. /*---------常用正则判断--------*/
  65. //#define PASSWORD_REGEX (@"[a-zA-Z0-9]{6,20}") // 6-20位密码
  66. #define CHINESS_REGEX (@"^[\\u4e00-\\u9fa5]+$") // 全中文字符
  67. #define MONEY_REGEX (@"^\\-?([0-9]{0,9})(\\.\\d{0,2})?$") // 金额 最多9位
  68. #define PHONE_REGEX (@"^[0-9]{11}") // 电话号码 11位
  69. #define VEFICODE_REGEX (@"^[0-9]{6}") // 验证码 6位
  70. #define PAYCODE_REGEX (@"^[0-9]{6}") // 密码
  71. #define PASSWORD_REGEX (@"^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,12}$") // 密码 6-12位字母和数字混合
  72. //#define IDCARD_REGEX (@"^[1-9][0-9]{5}(19|20)[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|30|31)|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}([0-9]|x|X)$") // 18位身份证号
  73. #define IDCARD_REGEX (@"^[0-9]{17}[0-9xX]$") // 18位身份证号
  74. #define PHONE_REGEX_FORMAT (@"^1[3-9]\\d{9}$") // 电话号码 11位
  75. #ifndef kSystemVersion
  76. #define kSystemVersion ([UIDevice currentDevice].systemVersion.doubleValue)
  77. #endif
  78. #define KSWeakSelf(weakSelf) __weak typeof(self) weakSelf = self;
  79. #define KObjNull (id)[NSNull null]
  80. //------------------------------------Debug/Release
  81. #ifdef DEBUG
  82. //Debug模式
  83. //...重新定义系统的NSLog
  84. #define NSLog(...) NSLog(__VA_ARGS__)
  85. #else
  86. //发布模式
  87. //...
  88. //屏蔽NSLog
  89. #define NSLog(...) {};
  90. #endif
  91. //----------------------ABOUT PRINTING LOG 打印日志 ----------------------------
  92. //Using dlog to print while in debug model. 调试状态下打印日志
  93. #ifdef DEBUG
  94. # define KSLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
  95. #else
  96. # define KSLog(...)
  97. #endif
  98. #define dispatch_main_sync_safe(block)\
  99. if ([NSThread isMainThread]) {\
  100. block();\
  101. } else {\
  102. dispatch_sync(dispatch_get_main_queue(), block);\
  103. }
  104. //2. 正式且 ARC 环境
  105. #ifndef weakObj
  106. #define weakObj(object) try {} @catch (...){} __weak __typeof__(object) object##_##weak_ = object;
  107. #endif
  108. #ifndef strongObj
  109. #define strongObj(object) try {} @catch (...){} __typeof__(object) object = object##_##weak_;
  110. #endif
  111. #define IS_IPAD [[UIDevice currentDevice].model hasPrefix:@"iPad"]
  112. #define KS_GET @"get"
  113. #define KS_POST @"post"
  114. #endif /* BaseMaroDefine_h */