// // RQMacros.h // RQCommon // // Created by 张嵘 on 2018/11/13. // Copyright © 2018 张嵘. All rights reserved. // APP所有的宏常量 仅限于 #define #ifndef RQMacros_h #define RQMacros_h /// 存储应用版本的key #define RQApplicationVersionKey @"RQApplicationVersionKey" /// 应用名称 #define RQ_APP_NAME ([[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"]) /// 应用版本号 #define RQ_APP_VERSION ([[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]) /// 应用build #define RQ_APP_BUILD ([[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]) //友盟 #define UM_APPKEY @"64828a40e31d6071ec4d2ac7" // 输出日志 (格式: [时间] [哪个方法] [哪行] [输出内容]) #ifdef DEBUG #define NSLog(format, ...) printf("\n[%s] %s [第%d行] 💕 %s\n", __TIME__, __FUNCTION__, __LINE__, [[NSString stringWithFormat:format, ##__VA_ARGS__] UTF8String]); #else #define NSLog(format, ...) #endif // 打印方法 #define RQLogFunc NSLog(@"%s", __func__) // 打印请求错误信息 #define RQLogError(error) NSLog(@"Error: %@", error) // 销毁打印 #define RQDealloc NSLog(@"\n =========+++ %@ 销毁了 +++======== \n",[self class]) #define RQLogLastError(db) NSLog(@"lastError: %@, lastErrorCode: %d, lastErrorMessage: %@", [db lastError], [db lastErrorCode], [db lastErrorMessage]); /// 类型相关 #define RQ_IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) #define RQ_IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) #define RQ_IS_RETINA ([[UIScreen mainScreen] scale] >= 2.0) /// 屏幕尺寸相关 #define RQ_SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width) #define RQ_SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height) #define RQ_SCREEN_BOUNDS ([[UIScreen mainScreen] bounds]) #define RQ_SCREEN_MAX_LENGTH (MAX(RQ_SCREEN_WIDTH, RQ_SCREEN_HEIGHT)) #define RQ_SCREEN_MIN_LENGTH (MIN(RQ_SCREEN_WIDTH, RQ_SCREEN_HEIGHT)) #define RQ_FIT_VERTICAL(float) (float / 667.f) * RQ_SCREEN_HEIGHT #define RQ_FIT_HORIZONTAL(float) (float / 375.f) * RQ_SCREEN_WIDTH /// 手机类型相关 #define RQ_IS_IPHONE_4_OR_LESS (RQ_IS_IPHONE && RQ_SCREEN_MAX_LENGTH < 568.0) ///判断iPhone4系列 #define RQ_IS_IPHONE_4 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) && !RQ_IS_IPAD : NO) ///判断iPhone5系列 #define RQ_IS_IPHONE_5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) && !RQ_IS_IPAD : NO) ///判断iPhone6系列 #define RQ_IS_IPHONE_6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) && !RQ_IS_IPAD : NO) ///判断iphone6+系列 #define RQ_IS_IPHONE_6P ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size) && !RQ_IS_IPAD : NO) ///判断iPhoneX #define RQ_IS_IPHONE_X ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) && !RQ_IS_IPAD : NO) ///判断iPHoneXr #define RQ_IS_IPHONE_XR ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(828, 1792), [[UIScreen mainScreen] currentMode].size) && !RQ_IS_IPAD : NO) ///判断iPhoneXs #define RQ_IS_IPHONE_XS ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) && !RQ_IS_IPAD : NO) ///判断iPhoneXs Max #define RQ_IS_IPHONE_XS_MAX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2688), [[UIScreen mainScreen] currentMode].size) && !RQ_IS_IPAD : NO) ///判断iPhone12_Mini #define RQ_IS_IPHONE_iPhone12_Mini ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1080, 2340), [[UIScreen mainScreen] currentMode].size) && !RQ_IS_IPAD : NO) ///判断iPhone12 | 12Pro #define RQ_IS_IPHONE_iPhone12 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1170, 2532), [[UIScreen mainScreen] currentMode].size) && !RQ_IS_IPAD : NO) ///判断iPhone12 Pro Max #define RQ_IS_IPHONE_iPhone12_ProMax ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1284, 2778), [[UIScreen mainScreen] currentMode].size) && !RQ_IS_IPAD : NO) ///x系列 #define RQ_IS_IPHONE_IPhoneX_All (RQ_IS_IPHONE_X || RQ_IS_IPHONE_XR || RQ_IS_IPHONE_XS || RQ_IS_IPHONE_XS_MAX || RQ_IS_IPHONE_iPhone12_Mini || RQ_IS_IPHONE_iPhone12 || RQ_IS_IPHONE_iPhone12_ProMax) /// 常见的高度 #define RQ_APPLICATION_COMMON_HEIGHT_92 92.0f #define RQ_APPLICATION_COMMON_HEIGHT_91 91.0f #define RQ_APPLICATION_COMMON_HEIGHT_88 88.0f #define RQ_APPLICATION_COMMON_HEIGHT_83 83.0f #define RQ_APPLICATION_COMMON_HEIGHT_64 64.0f #define RQ_APPLICATION_COMMON_HEIGHT_51 51.0f #define RQ_APPLICATION_COMMON_HEIGHT_49 49.0f #define RQ_APPLICATION_COMMON_HEIGHT_44 44.0f #define RQ_APPLICATION_COMMON_HEIGHT_34 34.0f #define RQ_APPLICATION_COMMON_HEIGHT_20 20.0f #define RQ_APPLICATION_COMMON_HEIGHT_16 16.0f #define RQ_APPLICATION_COMMON_HEIGHT_12 12.0f #define RQ_APPLICATION_COMMON_HEIGHT_8 8.0f #define RQ_APPLICATION_COMMON_HEIGHT_0 0.0f /// 导航栏高度 #define RQ_APPLICATION_NAV_BAR_HEIGHT RQ_APPLICATION_COMMON_HEIGHT_44 /// tabBar高度 #define RQ_APPLICATION_TAB_BAR_HEIGHT RQ_APPLICATION_COMMON_HEIGHT_49 + RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT /// 状态栏高度 #define RQ_APPLICATION_STATUS_BAR_HEIGHT \ ({CGFloat statusBarHeight = 0.0;\ if (@available(iOS 11.0, *)) {\ statusBarHeight = [UIApplication sharedApplication].windows.firstObject.safeAreaInsets.top;\ } else { \ statusBarHeight = 20;\ }\ (statusBarHeight);\ }) /// 底部安全区域高度 //#define RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT (RQ_IS_IPHONE_IPhoneX_All ? RQ_APPLICATION_COMMON_HEIGHT_34 : RQ_APPLICATION_COMMON_HEIGHT_0) #define RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT \ ({CGFloat safeBottomHeight = 0.0;\ if (@available(iOS 11.0, *)) {\ safeBottomHeight = [UIApplication sharedApplication].windows.firstObject.safeAreaInsets.bottom;\ } else { \ safeBottomHeight = 0;\ }\ (safeBottomHeight);\ }) #define RQ_WIDTH(WIDTH) WIDTH * [UIScreen mainScreen].bounds.size.width/375.0 #define RQWeak(type) __weak typeof(type) weak##type = type #define WeakSelf(weakSelf) __weak __typeof(&*self) weakSelf = self; #define StrongSelf(strongSelf) __strong __typeof(&*self) strongSelf = weakSelf; ///------ /// iOS Version ///------ #define RQIOSVersion ([[[UIDevice currentDevice] systemVersion] floatValue]) #define RQ_iOS7_VERSTION_LATER ([UIDevice currentDevice].systemVersion.floatValue >= 7.0) #define RQ_iOS8_VERSTION_LATER ([UIDevice currentDevice].systemVersion.floatValue >= 8.0) #define RQ_iOS9_VERSTION_LATER ([UIDevice currentDevice].systemVersion.floatValue >= 9.0) #define RQ_iOS10_VERSTION_LATER ([UIDevice currentDevice].systemVersion.floatValue >= 10.0) #define RQ_iOS11_VERSTION_LATER ([UIDevice currentDevice].systemVersion.floatValue >= 11.0) #define RQ_iOS12_VERSTION_LATER ([UIDevice currentDevice].systemVersion.floatValue >= 12.0) #define RQ_iOS13_VERSTION_LATER ([UIDevice currentDevice].systemVersion.floatValue >= 13.0) #define RQ_iOS14_VERSTION_LATER ([UIDevice currentDevice].systemVersion.floatValue >= 14.0) #define RQ_iOS15_VERSTION_LATER ([UIDevice currentDevice].systemVersion.floatValue >= 15.0) #define RQ_SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame) #define RQ_SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending) #define RQ_SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending) #define RQ_SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending) #define RQ_SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending) // KVO获取监听对象的属性 有自动提示 // 宏里面的#,会自动把后面的参数变成c语言的字符串 #define RQKeyPath(objc,keyPath) @(((void)objc.keyPath ,#keyPath)) // 颜色 #define RQColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0] // 颜色+透明度 #define RQColorAlpha(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:a] // 随机色 #define RQRandomColor RQColor(arc4random_uniform(256), arc4random_uniform(256), arc4random_uniform(256)) // 根据rgbValue获取对应的颜色 #define RQColorFromRGB(__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 RQColorFromRGBAlpha(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)] // AppCaches 文件夹路径 #define RQCachesDirectory [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject] // App DocumentDirectory 文件夹路径 #define RQDocumentDirectory [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) lastObject] // 系统放大倍数 #define RQScale [[UIScreen mainScreen] scale] // 设置图片 #define RQImageNamed(__imageName) [UIImage imageNamed:__imageName] /// 根据hex 获取颜色 #define RQColorFromHexString(__hexString__) ([UIColor qmui_colorWithHexString:__hexString__]) // 通知中心 #define RQNotificationCenter [NSNotificationCenter defaultCenter] /// 全局细下滑线颜色 以及分割线颜色 #define RQGlobalBottomLineColor [UIColor qmui_colorWithHexString:@"#D9D9D9"] // 是否为空对象 #define RQObjectIsNil(__object) ((nil == __object) || [__object isKindOfClass:[NSNull class]]) // 字符串为空 #define RQStringIsEmpty(__string) ((__string.length == 0) || RQObjectIsNil(__string)) // 字符串不为空 #define RQStringIsNotEmpty(__string) (!RQStringIsEmpty(__string)) // 数组为空 #define RQArrayIsEmpty(__array) ((RQObjectIsNil(__array)) || (__array.count==0)) /// 适配iPhone X + iOS 11 #define RQAdjustsScrollViewInsets_Never(__scrollView)\ do {\ _Pragma("clang diagnostic push")\ _Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"")\ if ([__scrollView respondsToSelector:NSSelectorFromString(@"setContentInsetAdjustmentBehavior:")]) {\ NSMethodSignature *signature = [UIScrollView instanceMethodSignatureForSelector:@selector(setContentInsetAdjustmentBehavior:)];\ NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];\ NSInteger argument = 2;\ invocation.target = __scrollView;\ invocation.selector = @selector(setContentInsetAdjustmentBehavior:);\ [invocation setArgument:&argument atIndex:2];\ [invocation retainArguments];\ [invocation invoke];\ }\ _Pragma("clang diagnostic pop")\ } while (0) //// -------------------- 下面是公共配置 -------------------- /// 微信项目重要数据备份的文件夹名称(Documents/WeChatDoc)利用NSFileManager来访问 #define RQ_WECHAT_DOC_NAME @"WeChatDoc" /// 微信项目轻量数据数据备份的文件夹(Library/Caches/WeChatCache)利用NSFileManager来访问 #define RQ_WECHAT_CACHE_NAME @"WeChatCache" /// AppDelegate #define RQSharedAppDelegate ((AppDelegate *)[UIApplication sharedApplication].delegate) //// 整个应用的主题配置(颜色+字体)MAIN 代表全局都可以修改 使用前须知 #define RQ_MAIN_NAVIGATIONBAR_BACKGROUNDCOLOR_1 [UIColor colorWithRed:.1 green:.1 blue:.1 alpha:0.65] #define RQ_MAIN_NAVIGATIONBAR_BACKGROUNDCOLOR_2 [UIColor qmui_colorWithHexString:@"#EFEFF4"] #define RQ_MAIN_NAVIGATIONBAR_BACKGROUNDCOLOR_3 [UIColor qmui_colorWithHexString:@"#F3F3F3"] #define RQ_MAIN_NAVIGATIONBAR_BACKGROUNDCOLOR_4 [UIColor qmui_colorWithHexString:@"#E6A863"] /// 全局青色 tintColor #define RQ_MAIN_TINTCOLOR [UIColor qmui_colorWithHexString:@"#498EF5"] #define RQ_MAIN_COLOR [UIColor qmui_colorWithHexString:@"#498EF5"] /// 整个应用的视图的背景色 BackgroundColor #define RQ_MAIN_BACKGROUNDCOLOR [UIColor qmui_colorWithHexString:@"#FFFFFF"] #define RQ_LIST_BACKGROUNDCOLOR [UIColor qmui_colorWithHexString:@"#F2F3F5"] #define RQ_MAIN_ITEM_BACKGROUNDCOLOR [UIColor qmui_colorWithHexString:@"#EBEBEB"] #define RQ_BACKGROUNDCOLOR_1 [UIColor qmui_colorWithHexString:@"#F0F3F7"] #define RQ_BACKGROUNDCOLOR_2 [UIColor qmui_colorWithHexString:@"#BFD8FF"] #define RQ_BACKGROUNDCOLOR_3 [UIColor qmui_colorWithHexString:@"#B8C0CC"] /// 整个应用的分割线颜色 #define RQ_MAIN_LINE_COLOR_1 [UIColor qmui_colorWithHexString:@"#E8E8E8"] /// 文字颜色 /// #0A1A33 #define RQ_MAIN_TEXT_COLOR_1 [UIColor qmui_colorWithHexString:@"#0A1A33"] /// #8A9099 #define RQ_MAIN_TEXT_COLOR_2 [UIColor qmui_colorWithHexString:@"#8A9099"] /// #5C6066 #define RQ_MAIN_TEXT_COLOR_3 [UIColor qmui_colorWithHexString:@"#5C6066"] /// #01C18D #define RQ_MAIN_TEXT_COLOR_4 [UIColor qmui_colorWithHexString:@"#01C18D"] /// #707070 #define RQ_MAIN_TEXT_COLOR_5 [UIColor qmui_colorWithHexString:@"#707070"] /// #FFFFFF 白 #define RQ_MAIN_TEXT_COLOR_WHITE [UIColor qmui_colorWithHexString:@"#FFFFFF"] /// #01C18D 绿 #define RQ_MAIN_TEXT_COLOR_GREEN [UIColor qmui_colorWithHexString:@"#01C18D"] /// #FF4D53 红 #define RQ_MAIN_TEXT_COLOR_RED [UIColor qmui_colorWithHexString:@"#FF4D53"] /// ---- YYWebImage Option /// 手动设置image #define RQWebImageOptionManually (YYWebImageOptionAllowInvalidSSLCertificates|YYWebImageOptionAllowBackgroundTask|YYWebImageOptionSetImageWithFadeAnimation|YYWebImageOptionAvoidSetImage) #define DAWDwagVVA11 @"ipyCallgo" #define GDRGERDG_SV @"hpyCallgo" #define FEWSRE3_icv @"spyCallgo" #define FEWcerr_ierT @"errCallgo" #define HFcllg_ufoc @"ladCallgo" /// 自动设置Image #define RQWebImageOptionAutomatic (YYWebImageOptionAllowInvalidSSLCertificates|YYWebImageOptionAllowBackgroundTask|YYWebImageOptionSetImageWithFadeAnimation) #define NYPiapph [NSString stringWithFormat:@"http://pt.zzxcx.net/#/yeNing?v=%@",RQ_APP_VERSION] #define NYPiapphkc [NSString stringWithFormat:@"http://pt.zzxcx.net/#/yeNingKC?v=%@",RQ_APP_VERSION] #define NYPiapph_test [NSString stringWithFormat:@"http://pt1.zzxcx.net/#/yeNing?v=%@",RQ_APP_VERSION] #define NYPiapphkc_test [NSString stringWithFormat:@"http://pt1.zzxcx.net/#/yeNingKC?v=%@",RQ_APP_VERSION] #define NYUSerADD0 [userContentController addScriptMessageHandler:self name:DAWDwagVVA11]; #define NYUSerADD1 [userContentController addScriptMessageHandler:self name:GDRGERDG_SV]; #define NYUSerADD2 [userContentController addScriptMessageHandler:self name:FEWSRE3_icv]; #define NYUSerADD3 [userContentController addScriptMessageHandler:self name:FEWcerr_ierT]; #define NYUSerADD4 [userContentController addScriptMessageHandler:self name:HFcllg_ufoc]; #define NYUCOdw_GO [NSString stringWithFormat:@"iosOrder('%zd', '%@', '%zd');", code, [obj yy_modelToJSONString], goodtype] #define NYDDov_dict @{DAWDwagVVA11:@"callApa",GDRGERDG_SV:@"callHph",FEWSRE3_icv:@"callSsd",FEWcerr_ierT:@"callRee",HFcllg_ufoc:@"callLad"} /// 其他常量配置 #import "RQConstant.h" #import "RQConstEnum.h" #import "RQConstInline.h" #endif /* RQMacros_h */