Common.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. //
  2. // Common.h
  3. // StudentDaya
  4. //
  5. // Created by Kyle on 2019/8/12.
  6. // Copyright © 2019 DayaMusic. All rights reserved.
  7. //
  8. #ifndef Common_h
  9. #import <Foundation/Foundation.h>
  10. #import <UIKit/UIKit.h>
  11. #define Common_h
  12. #import "MJExtension.h"
  13. #import <SDWebImage/UIImageView+WebCache.h>
  14. #import <NSString+Extension.h>
  15. #import <MSSBrowseDefine.h>
  16. #import <NSObject+KeyWindow.h>
  17. #import <UIView+KSLayer.h>
  18. #import <KSSafeObject.h>
  19. #import <NSDictionary+Extension.h>
  20. #import <UIControl+ButtonAction.h>
  21. #import <UIView+KSExtension.h>
  22. #import <UIViewController+KSExtension.h>
  23. #import <UIViewController+zhStatusBarStyle.h>
  24. #import <UIView+SubViewExtension.h>
  25. #import <NSObject+KSDateFormatter.h>
  26. #import <NSString+phone.h>
  27. #import <KSUploadManager.h>
  28. #define FONT_COLOR (HexRGB(0x333333))
  29. #define THEMECOLOR HexRGB(0x2DC7AA)
  30. #define ALcellWidth (37)
  31. // 延时调用宏
  32. #define dispatch_delay_block(when,time,block)\
  33. dispatch_time_t delayTime = dispatch_time(when, time);\
  34. dispatch_after(delayTime, dispatch_get_main_queue(),block);
  35. #define KS_GET @"get"
  36. #define KS_POST @"post"
  37. /*---------常用正则判断--------*/
  38. //#define PASSWORD_REGEX (@"[a-zA-Z0-9]{6,20}") // 6-20位密码
  39. #define CHINESS_REGEX (@"^[\\u4e00-\\u9fa5]+$") // 全中文字符
  40. #define MONEY_REGEX (@"^\\-?([0-9]{0,9})(\\.\\d{0,2})?$") // 金额 最多9位
  41. #define PHONE_REGEX (@"^[0-9]{11}") // 电话号码 11位
  42. #define VEFICODE_REGEX (@"^[0-9]{6}") // 验证码 6位
  43. #define PAYCODE_REGEX (@"^[0-9]{6}") // 密码
  44. #define PASSWORD_REGEX (@"^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,12}$") // 密码 6-12位字母和数字混合
  45. //#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位身份证号
  46. #define IDCARD_REGEX (@"^[0-9]{17}[0-9xX]$") // 18位身份证号
  47. #define PHONE_REGEX_FORMAT (@"^1[3-9]\\d{9}$") // 电话号码 11位
  48. /*---------------------------------------- 常见固态宏 ---------------------------------------
  49. */
  50. #define USER_DEFAULT [NSUserDefaults standardUserDefaults]
  51. #define FILE_MANAGER [NSFileManager defaultManager]
  52. #define NOTIFICATION_CENTER [NSNotificationCenter defaultCenter]
  53. #define SET_IMAGE(ImageName) [UIImage imageNamed:ImageName]
  54. #define SET_WORD_SIZE(size) [UIFont systemFontOfSize:size]
  55. #define SET_BOLD_WORD_SIZE(size) [UIFont boldSystemFontOfSize:size]
  56. #define Login [[USER_DEFAULT objectForKey:@"isLogin"] isEqualToString:@"isLogin"]
  57. /*---------------------------------------- 系统版本宏/等v/大v/大等v/小v/小等v ---------------------------------------
  58. */
  59. #define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
  60. #define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
  61. #define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
  62. #define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
  63. #define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
  64. #ifndef kSystemVersion
  65. #define kSystemVersion ([UIDevice currentDevice].systemVersion.doubleValue)
  66. #endif
  67. #ifndef kiOS6Later
  68. #define kiOS6Later (kSystemVersion >= 6)
  69. #endif
  70. #ifndef kiOS7Later
  71. #define kiOS7Later (kSystemVersion >= 7)
  72. #endif
  73. #ifndef kiOS8Later
  74. #define kiOS8Later (kSystemVersion >= 8)
  75. #endif
  76. #ifndef kiOS9Later
  77. #define kiOS9Later (kSystemVersion >= 9)
  78. #endif
  79. /*---------------------------------------- 判断手机型号 ---------------------------------------
  80. */
  81. #define IS_WIDESCREEN_4 (fabs((double)[[UIScreen mainScreen] bounds].size.height - (double)480) < __DBL_EPSILON__)
  82. #define IS_WIDESCREEN_5 (fabs((double)[[UIScreen mainScreen] bounds].size.height - (double)568) < __DBL_EPSILON__)
  83. #define IS_WIDESCREEN_6 (fabs((double)[[UIScreen mainScreen] bounds].size.height - (double)667) < __DBL_EPSILON__)
  84. #define IS_WIDESCREEN_6Plus (fabs((double)[[UIScreen mainScreen] bounds].size.height - (double)736) < __DBL_EPSILON__)
  85. #define IS_IPHONE_4 (IS_IPHONE && IS_WIDESCREEN_4)
  86. #define IS_IPHONE_5 (IS_IPHONE && IS_WIDESCREEN_5)
  87. #define IS_IPHONE_6 (IS_IPHONE && IS_WIDESCREEN_6)
  88. #define IS_IPHONE_6Plus (IS_IPHONE && IS_WIDESCREEN_6Plus)
  89. /*---------------------------------------- 判断设备类型 ---------------------------------------
  90. */
  91. #define IS_IPHONE ([[[UIDevice currentDevice] model] isEqualToString: @"iPhone"] || [[[UIDevice currentDevice] model] isEqualToString: @"iPhone Simulator"])
  92. #define IS_IPOD ([[[UIDevice currentDevice] model] isEqualToString: @"iPod touch"])
  93. #define IS_IPAD [[UIDevice currentDevice].model hasPrefix:@"iPad"]
  94. /*---------------------------------------- 常见尺寸宏 ---------------------------------------
  95. */
  96. #define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
  97. #define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)
  98. #define STATUS_BAR_HEIGHT 20.0f
  99. #define NAVIGATION_BAR_HEIGHT 44.0f
  100. #define NAVIGATION_BAR_HEIGHT_SYS IS_OS_7_OR_LATER ? 64.0f:44.0f
  101. #define TAB_BAB_HEIGHT 49.0f
  102. #define kpadding 10.0f
  103. #define kScreenWidth [UIScreen mainScreen].bounds.size.width
  104. #define kScreenHeight [UIScreen mainScreen].bounds.size.height
  105. #define kWindow [UIApplication sharedApplication].keyWindow
  106. #define KLandscapeWidth ([UIScreen mainScreen].bounds.size.width > [UIScreen mainScreen].bounds.size.height ? [UIScreen mainScreen].bounds.size.width : [UIScreen mainScreen].bounds.size.height)
  107. #define KLandscapeHeight ([UIScreen mainScreen].bounds.size.width > [UIScreen mainScreen].bounds.size.height ? [UIScreen mainScreen].bounds.size.height : [UIScreen mainScreen].bounds.size.width)
  108. #define KPortraitWidth ([UIScreen mainScreen].bounds.size.width > [UIScreen mainScreen].bounds.size.height ? [UIScreen mainScreen].bounds.size.height : [UIScreen mainScreen].bounds.size.width)
  109. #define KPortraitHeight ([UIScreen mainScreen].bounds.size.width > [UIScreen mainScreen].bounds.size.height ? [UIScreen mainScreen].bounds.size.width : [UIScreen mainScreen].bounds.size.height)
  110. //iPhoneX机型判断
  111. #define IS_iPhoneX ({\
  112. BOOL iPhoneXSeries = NO;\
  113. if (UIDevice.currentDevice.userInterfaceIdiom != UIUserInterfaceIdiomPhone) {\
  114. iPhoneXSeries = NO;\
  115. }\
  116. else if (@available(iOS 11.0, *)) {\
  117. UIWindow *mainWindow = [[[UIApplication sharedApplication] delegate] window];\
  118. if (mainWindow.safeAreaInsets.bottom > 0.0) {\
  119. iPhoneXSeries = YES;\
  120. }\
  121. }\
  122. (iPhoneXSeries);\
  123. })
  124. //状态栏高度配置
  125. #define STATUS_GAP (IS_iPhoneX? 44 : 20)
  126. //设备底部安全距离配置
  127. #define iPhoneXSafeBottomMargin (IS_iPhoneX ? 34.f : 0.f)
  128. #define iPhoneXSafeTopMargin ((IS_iPhoneX ? 24.f : 0.f))
  129. #define IOS11 @available(iOS 11.0, *)
  130. //#define kTabBarHeight 49.0
  131. #define kTabBarHeight (IS_iPhoneX ? 83 : 49)
  132. #define kNaviBarHeight (IS_iPhoneX ? 88.0 : 64.0)
  133. #define BLOCK_EXEC(block, ...) !block ?: block(__VA_ARGS__);
  134. #define KS_ImageName(string1,string2) [NSString stringWithFormat:@"%@%@",string1,string2]
  135. #define PlaceholderImage @"grzl_image_tx"//普通占位图
  136. #define PERSON_PLACEHOLD @"tx_img_mrtx" //头像占位图
  137. #define ADD_PLACEHOLD @"kjxq_image_mrt"
  138. #define NetWorking_Msg dic[@"message"]
  139. #define LOGO_PLACEHOLDER (@"bjgrzl_icon_mrtx")
  140. //极光推送
  141. #define JPushAppKey @"278689c14789ecb1e60f7e7e"
  142. #define JPushChannel @"ylj"
  143. //#import "JPUSHService.h"
  144. //高德
  145. #define kAmapAppKey @"0814b91fe45b16a13c10136350ea7fcf"
  146. //设置经度
  147. #define SetLongitude(longitude) [[NSUserDefaults standardUserDefaults] setFloat:longitude forKey:@"longitude"];
  148. //设置纬度
  149. #define SetLatitude(latitude) [[NSUserDefaults standardUserDefaults] setFloat:latitude forKey:@"latitude"];
  150. //设置城市
  151. #define SetCity(city) [[NSUserDefaults standardUserDefaults] setValue:city forKey:@"city"];
  152. //获取经纬度
  153. #define GetLongitude [[NSUserDefaults standardUserDefaults] floatForKey:@"longitude"]
  154. #define GetLatitude [[NSUserDefaults standardUserDefaults] floatForKey:@"latitude"]
  155. #define GetCity [[NSUserDefaults standardUserDefaults] valueForKey:@"city"]
  156. #define DefaultLocationTimeout 10
  157. #define DefaultReGeocodeTimeout 5
  158. #define KSWeakSelf(weakSelf) __weak typeof(self) weakSelf = self;
  159. /*---------------------------------------- 视图尺寸 ---------------------------------------
  160. */
  161. #define CONTENT_VIEW_HEIGHT_NO_TAB_BAR (SCREEN_HEIGHT - STATUS_BAR_HEIGHT - NAVIGATION_BAR_HEIGHT)
  162. #define CONTENT_VIEW_HEIGHT_TAB_BAR (CONTENT_VIEW_HEIGHT_NO_TAB_BAR - TAB_TAB_HEIGHT)
  163. /*---------------------------------------- 是否Retina ---------------------------------------
  164. */
  165. #define isRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? \
  166. CGSizeEqualToSize(CGSizeMake(640, 960), \
  167. [[UIScreen mainScreen] currentMode].size) : \
  168. NO)
  169. /*---------------------------------------- RGBA颜色 ---------------------------------------
  170. */
  171. #define RGBCOLOR(r, g, b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]
  172. #define RGBACOLOR(r, g, b, a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)]
  173. #define TEXT_COLOR ([UIColor grayColor])
  174. #define SEPARATOR_COLOR ([UIColor colorWithRed:238/250.0 green:238/250.0 blue:238/250.0 alpha:1])
  175. #define STATUS_BAR_COLOR ([UIColor colorWithRed:43/255.0 green:43/255.0 blue:45/255.0 alpha:1])
  176. /*---------------------------------------- 系统警告框 ---------------------------------------
  177. */
  178. #define ALERT_SHOW_MSG(title,msg,cancleT,otherT) UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:cancleT otherButtonTitles:otherT, nil];\
  179. [alertView show];
  180. #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];\
  181. [actionSheet showInView:self.view];
  182. /*---------------------------------------- Debug调试 ---------------------------------------
  183. */
  184. //Perform tightly in the debug mode
  185. #ifdef DEBUG
  186. #ifndef DLog
  187. # define DLog(fmt, ...) {NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);}
  188. #endif
  189. #ifndef ELog
  190. # define ELog(err) {if(err) DLog(@"%@", err)}
  191. #endif
  192. #else
  193. #ifndef DLog
  194. # define DLog(...)
  195. #endif
  196. #ifndef ELog
  197. # define ELog(err)
  198. #endif
  199. #endif
  200. // ALog always displays output regardless of the DEBUG setting
  201. #ifndef ALog
  202. # define ALog(fmt, ...) {NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);};
  203. #endif
  204. #define GlobalColor RGBCOLOR(11, 90, 224)
  205. #define BGColor RGBCOLOR(249, 250, 252)
  206. /*
  207. iPhone X适配注意事项:
  208. 1. iPhone X新增了安全区域的概念,在ACMacros.h文件中写了4个关于适配iPhone X的内联函数
  209. 2. 原来表示状态栏的高度用statusMarginToTop()获取,导航栏高度用navMarginToTop()获取(导航栏高度iPhone X和其他机型之间没有变化)
  210. 3. 底部的安全区域用bottomMarginToBottom()获取。
  211. 4. 当App横屏启动时(当前控制器并不支持横屏情况下)这时候,这时候通过statusMarginToTop()函数获取状态栏高度获取不到,这时候使用leftMarginToLeft()获取。
  212. statusMarginToTop是状态栏的高度,navMarginToTop是导航栏的高度,leftMarginToLeft(),topMarginToTop(),bottomMarginToBottom()
  213. 是安全区域。。你把项目里面64替换成statusMarginToTop()+navMarginToTop().整个页面的高度多减一个bottomMarginToBottom()
  214. */
  215. static inline CGFloat leftMarginToLeft() {
  216. #ifdef __IPHONE_11_0
  217. if (@available(iOS 11.0, *)) {
  218. return [UIApplication sharedApplication].keyWindow.safeAreaInsets.left;
  219. }
  220. #endif
  221. return 0;
  222. }
  223. static inline CGFloat topMarginToTop() {
  224. #ifdef __IPHONE_11_0
  225. if (@available(iOS 11.0, *)) {
  226. return [UIApplication sharedApplication].keyWindow.safeAreaInsets.top;
  227. }
  228. #endif
  229. return 0;
  230. }
  231. static inline CGFloat statusMarginToTop() {
  232. CGFloat height = [[UIApplication sharedApplication] statusBarFrame].size.height;
  233. if (height < leftMarginToLeft()) {
  234. height = leftMarginToLeft();
  235. }
  236. return height;
  237. }
  238. static inline CGFloat navMarginToTop() {
  239. return 44;
  240. }
  241. static inline CGFloat bottomMarginToBottom() {
  242. #ifdef __IPHONE_11_0
  243. if (@available(iOS 11.0, *)) {
  244. return [UIApplication sharedApplication].keyWindow.safeAreaInsets.bottom;
  245. }
  246. #endif
  247. return 0;
  248. }
  249. //------------------------------------Debug/Release
  250. #ifdef DEBUG
  251. //Debug模式
  252. //...重新定义系统的NSLog
  253. #define NSLog(...) NSLog(__VA_ARGS__)
  254. #else
  255. //发布模式
  256. //...
  257. //屏蔽NSLog
  258. #define NSLog(...) {};
  259. #endif
  260. //----------------------ABOUT PRINTING LOG 打印日志 ----------------------------
  261. //Using dlog to print while in debug model. 调试状态下打印日志
  262. #ifdef DEBUG
  263. # define KSLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
  264. #else
  265. # define KSLog(...)
  266. #endif
  267. #endif /* Common_h */