Common.h 13 KB

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