123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334 |
- //
- // Common.h
- // StudentDaya
- //
- // Created by Kyle on 2019/8/12.
- // Copyright © 2019 DayaMusic. All rights reserved.
- //
- #ifndef Common_h
- #import <Foundation/Foundation.h>
- #import <UIKit/UIKit.h>
- #define Common_h
- #import "MJExtension.h"
- #import "NSString+Extension.h"
- #import <UIImageView+WebCache.h>
- #import "MSSBrowseDefine.h"
- #import "NSObject+KeyWindow.h"
- #define FONT_COLOR (HexRGB(0x333333))
- #define THEMECOLOR HexRGB(0x2DC7AA)
- #define ALcellWidth (37)
- // 延时调用宏
- #define dispatch_delay_block(when,time,block)\
- dispatch_time_t delayTime = dispatch_time(when, time);\
- dispatch_after(delayTime, dispatch_get_main_queue(),block);
- #define KS_GET @"get"
- #define KS_POST @"post"
- /*---------常用正则判断--------*/
- //#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位
- /*---------------------------------------- 常见固态宏 ---------------------------------------
- */
- #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 Login [[USER_DEFAULT objectForKey:@"isLogin"] isEqualToString:@"isLogin"]
- /*---------------------------------------- 系统版本宏/等v/大v/大等v/小v/小等v ---------------------------------------
- */
- #define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
- #define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
- #define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
- #define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
- #define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
- #ifndef kSystemVersion
- #define kSystemVersion ([UIDevice currentDevice].systemVersion.doubleValue)
- #endif
- #ifndef kiOS6Later
- #define kiOS6Later (kSystemVersion >= 6)
- #endif
- #ifndef kiOS7Later
- #define kiOS7Later (kSystemVersion >= 7)
- #endif
- #ifndef kiOS8Later
- #define kiOS8Later (kSystemVersion >= 8)
- #endif
- #ifndef kiOS9Later
- #define kiOS9Later (kSystemVersion >= 9)
- #endif
- /*---------------------------------------- 判断手机型号 ---------------------------------------
- */
- #define IS_WIDESCREEN_4 (fabs((double)[[UIScreen mainScreen] bounds].size.height - (double)480) < __DBL_EPSILON__)
- #define IS_WIDESCREEN_5 (fabs((double)[[UIScreen mainScreen] bounds].size.height - (double)568) < __DBL_EPSILON__)
- #define IS_WIDESCREEN_6 (fabs((double)[[UIScreen mainScreen] bounds].size.height - (double)667) < __DBL_EPSILON__)
- #define IS_WIDESCREEN_6Plus (fabs((double)[[UIScreen mainScreen] bounds].size.height - (double)736) < __DBL_EPSILON__)
- #define IS_IPHONE_4 (IS_IPHONE && IS_WIDESCREEN_4)
- #define IS_IPHONE_5 (IS_IPHONE && IS_WIDESCREEN_5)
- #define IS_IPHONE_6 (IS_IPHONE && IS_WIDESCREEN_6)
- #define IS_IPHONE_6Plus (IS_IPHONE && IS_WIDESCREEN_6Plus)
- /*---------------------------------------- 判断设备类型 ---------------------------------------
- */
- #define IS_IPHONE ([[[UIDevice currentDevice] model] isEqualToString: @"iPhone"] || [[[UIDevice currentDevice] model] isEqualToString: @"iPhone Simulator"])
- #define IS_IPOD ([[[UIDevice currentDevice] model] isEqualToString: @"iPod touch"])
- #define IS_IPAD [[UIDevice currentDevice].model hasPrefix:@"iPad"]
- /*---------------------------------------- 常见尺寸宏 ---------------------------------------
- */
- #define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
- #define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)
- #define STATUS_BAR_HEIGHT 20.0f
- #define NAVIGATION_BAR_HEIGHT 44.0f
- #define NAVIGATION_BAR_HEIGHT_SYS IS_OS_7_OR_LATER ? 64.0f:44.0f
- #define TAB_BAB_HEIGHT 49.0f
- #define kpadding 10.0f
- #define kScreenWidth [UIScreen mainScreen].bounds.size.width
- #define kScreenHeight [UIScreen mainScreen].bounds.size.height
- #define kWindow [UIApplication sharedApplication].keyWindow
- #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)
- //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))
- #define IOS11 @available(iOS 11.0, *)
- //#define kTabBarHeight 49.0
- #define kTabBarHeight (IS_iPhoneX ? 83 : 49)
- #define kNaviBarHeight (IS_iPhoneX ? 88.0 : 64.0)
- #define BLOCK_EXEC(block, ...) !block ?: block(__VA_ARGS__);
- #define KS_ImageName(string1,string2) [NSString stringWithFormat:@"%@%@",string1,string2]
- #define PlaceholderImage @"grzl_image_tx"//普通占位图
- #define PERSON_PLACEHOLD @"tx_img_mrtx" //头像占位图
- #define ADD_PLACEHOLD @"kjxq_image_mrt"
- #define NetWorking_Msg dic[@"message"]
- #define LOGO_PLACEHOLDER (@"bjgrzl_icon_mrtx")
- //极光推送
- #define JPushAppKey @"278689c14789ecb1e60f7e7e"
- #define JPushChannel @"ylj"
- //#import "JPUSHService.h"
- //高德
- #define kAmapAppKey @"0814b91fe45b16a13c10136350ea7fcf"
- //设置经度
- #define SetLongitude(longitude) [[NSUserDefaults standardUserDefaults] setFloat:longitude forKey:@"longitude"];
- //设置纬度
- #define SetLatitude(latitude) [[NSUserDefaults standardUserDefaults] setFloat:latitude forKey:@"latitude"];
- //设置城市
- #define SetCity(city) [[NSUserDefaults standardUserDefaults] setValue:city forKey:@"city"];
- //获取经纬度
- #define GetLongitude [[NSUserDefaults standardUserDefaults] floatForKey:@"longitude"]
- #define GetLatitude [[NSUserDefaults standardUserDefaults] floatForKey:@"latitude"]
- #define GetCity [[NSUserDefaults standardUserDefaults] valueForKey:@"city"]
- #define DefaultLocationTimeout 10
- #define DefaultReGeocodeTimeout 5
- #define KSWeakSelf(weakSelf) __weak typeof(self) weakSelf = self;
- /*---------------------------------------- 视图尺寸 ---------------------------------------
- */
- #define CONTENT_VIEW_HEIGHT_NO_TAB_BAR (SCREEN_HEIGHT - STATUS_BAR_HEIGHT - NAVIGATION_BAR_HEIGHT)
- #define CONTENT_VIEW_HEIGHT_TAB_BAR (CONTENT_VIEW_HEIGHT_NO_TAB_BAR - TAB_TAB_HEIGHT)
- /*---------------------------------------- 是否Retina ---------------------------------------
- */
- #define isRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? \
- CGSizeEqualToSize(CGSizeMake(640, 960), \
- [[UIScreen mainScreen] currentMode].size) : \
- NO)
- /*---------------------------------------- RGBA颜色 ---------------------------------------
- */
- #define RGBCOLOR(r, g, b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]
- #define RGBACOLOR(r, g, b, a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)]
- #define TEXT_COLOR ([UIColor grayColor])
- #define SEPARATOR_COLOR ([UIColor colorWithRed:238/250.0 green:238/250.0 blue:238/250.0 alpha:1])
- #define STATUS_BAR_COLOR ([UIColor colorWithRed:43/255.0 green:43/255.0 blue:45/255.0 alpha:1])
- /*---------------------------------------- 系统警告框 ---------------------------------------
- */
- #define ALERT_SHOW_MSG(title,msg,cancleT,otherT) UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:cancleT otherButtonTitles:otherT, nil];\
- [alertView show];
- #define ACTION_SHOW_MSG(title,cancleT,destructiveT,otherT,otherTT) UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:title delegate:self cancelButtonTitle:cancleT destructiveButtonTitle:destructiveT otherButtonTitles:otherT,otherTT, nil];\
- [actionSheet showInView:self.view];
- /*---------------------------------------- Debug调试 ---------------------------------------
- */
- //Perform tightly in the debug mode
- #ifdef DEBUG
- #ifndef DLog
- # define DLog(fmt, ...) {NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);}
- #endif
- #ifndef ELog
- # define ELog(err) {if(err) DLog(@"%@", err)}
- #endif
- #else
- #ifndef DLog
- # define DLog(...)
- #endif
- #ifndef ELog
- # define ELog(err)
- #endif
- #endif
- // ALog always displays output regardless of the DEBUG setting
- #ifndef ALog
- # define ALog(fmt, ...) {NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);};
- #endif
- #define GlobalColor RGBCOLOR(11, 90, 224)
- #define BGColor RGBCOLOR(249, 250, 252)
- /*
- iPhone X适配注意事项:
- 1. iPhone X新增了安全区域的概念,在ACMacros.h文件中写了4个关于适配iPhone X的内联函数
- 2. 原来表示状态栏的高度用statusMarginToTop()获取,导航栏高度用navMarginToTop()获取(导航栏高度iPhone X和其他机型之间没有变化)
- 3. 底部的安全区域用bottomMarginToBottom()获取。
- 4. 当App横屏启动时(当前控制器并不支持横屏情况下)这时候,这时候通过statusMarginToTop()函数获取状态栏高度获取不到,这时候使用leftMarginToLeft()获取。
-
- statusMarginToTop是状态栏的高度,navMarginToTop是导航栏的高度,leftMarginToLeft(),topMarginToTop(),bottomMarginToBottom()
- 是安全区域。。你把项目里面64替换成statusMarginToTop()+navMarginToTop().整个页面的高度多减一个bottomMarginToBottom()
- */
- static inline CGFloat leftMarginToLeft() {
- #ifdef __IPHONE_11_0
- if (@available(iOS 11.0, *)) {
- return [UIApplication sharedApplication].keyWindow.safeAreaInsets.left;
- }
- #endif
- return 0;
- }
- static inline CGFloat topMarginToTop() {
- #ifdef __IPHONE_11_0
- if (@available(iOS 11.0, *)) {
- return [UIApplication sharedApplication].keyWindow.safeAreaInsets.top;
- }
- #endif
- return 0;
- }
- static inline CGFloat statusMarginToTop() {
- CGFloat height = [[UIApplication sharedApplication] statusBarFrame].size.height;
- if (height < leftMarginToLeft()) {
- height = leftMarginToLeft();
- }
- return height;
- }
- static inline CGFloat navMarginToTop() {
- return 44;
- }
- static inline CGFloat bottomMarginToBottom() {
- #ifdef __IPHONE_11_0
- if (@available(iOS 11.0, *)) {
- return [UIApplication sharedApplication].keyWindow.safeAreaInsets.bottom;
- }
- #endif
- return 0;
- }
- //------------------------------------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
- #endif /* Common_h */
|