| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- //
- // BaseMaroDefine.h
- // KSToolsModule
- //
- // Created by 王智 on 2024/1/15.
- //
- #ifndef BaseMaroDefine_h
- #define BaseMaroDefine_h
- #define BLOCK_EXEC(block, ...) !block ?: block(__VA_ARGS__);
- #pragma mark ------ 宽高相关
- #define kScreenWidth [UIScreen mainScreen].bounds.size.width
- #define kScreenHeight [UIScreen mainScreen].bounds.size.height
- #define KLandscapeWidth ([UIScreen mainScreen].bounds.size.width > [UIScreen mainScreen].bounds.size.height ? [UIScreen mainScreen].bounds.size.width : [UIScreen mainScreen].bounds.size.height)
- #define KLandscapeHeight ([UIScreen mainScreen].bounds.size.width > [UIScreen mainScreen].bounds.size.height ? [UIScreen mainScreen].bounds.size.height : [UIScreen mainScreen].bounds.size.width)
- #define KPortraitWidth ([UIScreen mainScreen].bounds.size.width > [UIScreen mainScreen].bounds.size.height ? [UIScreen mainScreen].bounds.size.height : [UIScreen mainScreen].bounds.size.width)
- #define KPortraitHeight ([UIScreen mainScreen].bounds.size.width > [UIScreen mainScreen].bounds.size.height ? [UIScreen mainScreen].bounds.size.width : [UIScreen mainScreen].bounds.size.height)
- #define kTabBarHeight (IS_iPhoneX ? 83 : 49)
- #define kNaviBarHeight (IS_iPhoneX ? 88.0 : 64.0)
- //iPhoneX机型判断
- #define IS_iPhoneX ({\
- BOOL iPhoneXSeries = NO;\
- if (UIDevice.currentDevice.userInterfaceIdiom != UIUserInterfaceIdiomPhone) {\
- iPhoneXSeries = NO;\
- }\
- else if (@available(iOS 11.0, *)) {\
- UIWindow *mainWindow = [[[UIApplication sharedApplication] delegate] window];\
- if (mainWindow.safeAreaInsets.bottom > 0.0) {\
- iPhoneXSeries = YES;\
- }\
- }\
- (iPhoneXSeries);\
- })
- //状态栏高度配置
- #define STATUS_GAP (IS_iPhoneX? 44 : 20)
- //设备底部安全距离配置
- #define iPhoneXSafeBottomMargin (IS_iPhoneX ? 34.f : 0.f)
- #define iPhoneXSafeTopMargin ((IS_iPhoneX ? 24.f : 0.f))
- #pragma mark ------ 字体比例和宽高比例 (暂时可能不需要使用)
- /**宽度比例*/
- #define KS_ScaleWidth(__VA_ARGS__) ([UIScreen mainScreen].bounds.size.width/375)*(__VA_ARGS__)
- /**高度比例*/
- #define KS_ScaleHeight(__VA_ARGS__) ([UIScreen mainScreen].bounds.size.height/667)*(__VA_ARGS__)
- /**全局字体*/
- #define GlobelNormalFont(__VA_ARGS__) ([UIFont systemFontOfSize:KS_ScaleFont(__VA_ARGS__)])
- /**字体比例*/
- #define KS_ScaleFont(__VA_ARGS__) ([UIScreen mainScreen].bounds.size.width/375)*(__VA_ARGS__)
- #pragma mark----- 颜色
- #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]
- #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)]
- // 延时调用宏
- #define dispatch_delay_block(when,time,block)\
- dispatch_time_t delayTime = dispatch_time(when, time);\
- dispatch_after(delayTime, dispatch_get_main_queue(),block);
- /*---------------------------------------- 常见固态宏 ---------------------------------------
- */
- #define USER_DEFAULT [NSUserDefaults standardUserDefaults]
- #define FILE_MANAGER [NSFileManager defaultManager]
- #define NOTIFICATION_CENTER [NSNotificationCenter defaultCenter]
- #define SET_IMAGE(ImageName) [UIImage imageNamed:ImageName]
- #define SET_WORD_SIZE(size) [UIFont systemFontOfSize:size]
- #define SET_BOLD_WORD_SIZE(size) [UIFont boldSystemFontOfSize:size]
- #define UserDefault(_key_) [[NSUserDefaults standardUserDefaults] objectForKey:_key_]
- #define UserDefaultSet(_value_,_key_) ([[NSUserDefaults standardUserDefaults] setValue:_value_ forKey:_key_])
- /*---------常用正则判断--------*/
- //#define PASSWORD_REGEX (@"[a-zA-Z0-9]{6,20}") // 6-20位密码
- #define CHINESS_REGEX (@"^[\\u4e00-\\u9fa5]+$") // 全中文字符
- #define MONEY_REGEX (@"^\\-?([0-9]{0,9})(\\.\\d{0,2})?$") // 金额 最多9位
- #define PHONE_REGEX (@"^[0-9]{11}") // 电话号码 11位
- #define VEFICODE_REGEX (@"^[0-9]{6}") // 验证码 6位
- #define PAYCODE_REGEX (@"^[0-9]{6}") // 密码
- #define PASSWORD_REGEX (@"^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,12}$") // 密码 6-12位字母和数字混合
- //#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位身份证号
- #define IDCARD_REGEX (@"^[0-9]{17}[0-9xX]$") // 18位身份证号
- #define PHONE_REGEX_FORMAT (@"^1[3-9]\\d{9}$") // 电话号码 11位
- #ifndef kSystemVersion
- #define kSystemVersion ([UIDevice currentDevice].systemVersion.doubleValue)
- #endif
- #define KSWeakSelf(weakSelf) __weak typeof(self) weakSelf = self;
- #define KObjNull (id)[NSNull null]
- //------------------------------------Debug/Release
- #ifdef DEBUG
- //Debug模式
- //...重新定义系统的NSLog
- #define NSLog(...) NSLog(__VA_ARGS__)
- #else
- //发布模式
- //...
- //屏蔽NSLog
- #define NSLog(...) {};
- #endif
- //----------------------ABOUT PRINTING LOG 打印日志 ----------------------------
- //Using dlog to print while in debug model. 调试状态下打印日志
- #ifdef DEBUG
- # define KSLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
- #else
- # define KSLog(...)
- #endif
- #define dispatch_main_sync_safe(block)\
- if ([NSThread isMainThread]) {\
- block();\
- } else {\
- dispatch_sync(dispatch_get_main_queue(), block);\
- }
- //2. 正式且 ARC 环境
- #ifndef weakObj
- #define weakObj(object) try {} @catch (...){} __weak __typeof__(object) object##_##weak_ = object;
- #endif
- #ifndef strongObj
- #define strongObj(object) try {} @catch (...){} __typeof__(object) object = object##_##weak_;
- #endif
- #define IS_IPAD [[UIDevice currentDevice].model hasPrefix:@"iPad"]
- #define KS_GET @"get"
- #define KS_POST @"post"
- #endif /* BaseMaroDefine_h */
|