RDSConstant.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. //
  2. // RDSConstant.h
  3. // singleProduct
  4. //
  5. // Created by coderYK on 2018/4/26.
  6. // Copyright © 2018年 coderYK. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. //-------------------打印--------------------
  10. #ifdef DEBUG
  11. #define NEED_OUTPUT_LOG 1
  12. #else
  13. #define NEED_OUTPUT_LOG 0
  14. #endif
  15. #if NEED_OUTPUT_LOG
  16. #define DDLog(xx, ...) NSLog(@"%s(%d): " xx, __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
  17. #else
  18. #define DDLog(xx, ...) nil
  19. #endif
  20. // NSLog打印不全 加入后会导致控制台输出不显示时间 [[NSDate dateWithTimeIntervalSinceNow:0] timeIntervalSince1970]*1000
  21. #ifdef DEBUG
  22. #define NSLog(...) printf("%f %s\n",[[NSDate date] timeIntervalSince1970],[[NSString stringWithFormat:__VA_ARGS__]UTF8String]);
  23. #else
  24. #define NSLog(FORMAT, ...) nil
  25. #endif
  26. //-------------------打印--------------------
  27. #define kGetTimeNow [NSString stringWithFormat:@"%.0f", ([[NSDate dateWithTimeIntervalSinceNow:0] timeIntervalSince1970]*1000)]
  28. #define objectOrNull(obj) ((obj) ? (obj) : [NSNull null])
  29. #define objectOrEmptyStr(obj) ((obj) ? (obj) : @"")
  30. //判断字符串是否为空
  31. #define kNULLString(string) ((![string isKindOfClass:[NSString class]])||[string isEqualToString:@""] || (string == nil) || [string isEqualToString:@""] || [string isKindOfClass:[NSNull class]]||[[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length]==0)
  32. #define isNull(x) (!x || [x isKindOfClass:[NSNull class]])
  33. #define toInt(x) (isNull(x) ? 0 : [x intValue])
  34. #define isEmptyString(x) (isNull(x) || [x isEqual:@""] || [x isEqual:@"(null)"])
  35. #define sleep(s); [NSThread sleepForTimeInterval:s];
  36. #define Syn(x) @synthesize x = _##x
  37. #define BoldSystemFont(size) [UIFont boldSystemFontOfSize:size]
  38. #define systemFont(size) [UIFont systemFontOfSize:size]
  39. #define beginAutoPool NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; {
  40. #define endAutoPool } [pool release];
  41. #define skipspace(c) while (isspace(*c)) ++c
  42. #define skipUntil(c,x) while (x != *c) ++c
  43. #define TheWindowHeight ([UIDevice isAfterOS7] ? [UIScreen mainScreen].bounds.size.height : ([UIScreen mainScreen].bounds.size.height - 20))
  44. #define isIOS7 [[UIDevice currentDevice].systemVersion doubleValue]>=7.0?YES:NO
  45. #define isIOS8 [[UIDevice currentDevice].systemVersion doubleValue]>=8.0?YES:NO
  46. #define isIOS9 [[UIDevice currentDevice].systemVersion doubleValue]>=9.0?YES:NO
  47. #define isIOS10 [[UIDevice currentDevice].systemVersion doubleValue]>=10.0?YES:NO
  48. #define isIOS11 [[UIDevice currentDevice].systemVersion doubleValue]>=11.0?YES:NO
  49. #define kSYSTEM_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]
  50. #define kSTATUSBAR_HEIGHT [[UIApplication sharedApplication] statusBarFrame].size.height
  51. #define kNAVBAR_HEIGHT (44.f + ((kSYSTEM_VERSION >= 7) ? kSTATUSBAR_HEIGHT : 0))
  52. #define FULL_WIDTH SCREEN_WIDTH
  53. #define FULL_HEIGHT (SCREEN_HEIGHT - ((kSYSTEM_VERSION >= 7) ? 0 : kSTATUSBAR_HEIGHT))
  54. #define CONTENT_HEIGHT (FULL_HEIGHT - NAVBAR_HEIGHT)
  55. // 屏幕高度
  56. #define SCREEN_HEIGHT [[UIScreen mainScreen] bounds].size.height
  57. // 屏幕宽度
  58. #define SCREEN_WIDTH [[UIScreen mainScreen] bounds].size.width
  59. #define kSCALE_WIDTH_6 (SCREEN_WIDTH/375)
  60. #define kSCALE_HEIGHT_6 (SCREEN_HEIGHT/667)
  61. #define kSCALE_WIDTH_X (SCREEN_WIDTH/414)
  62. #define kSPACE_EDGE_RIGHT_LEFT (IPHONE4OR5 ? 10 : 20)
  63. #define IPAD9_7 SCREEN_WIDTH == 768
  64. #define IPHONE4OR5 ( [ [ UIScreen mainScreen ] bounds ].size.width == 320 )
  65. #define IPhoneX (SCREEN_HEIGHT == 812.0f || SCREEN_HEIGHT == 896.0f)
  66. #define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  67. #define kStatusBarHeight (IPhoneX ? 44 : 20) // 状态栏高度
  68. #define AdaptTabHeight (IPhoneX ? 34 : 0) // Tab bar 圆角部分高度
  69. #define kNavHeight (IPhoneX ? 88 : 64) // 导航
  70. #define kTabbarHeight (IPhoneX ? 83 : 49) // 分栏
  71. #define kUserDefaults [NSUserDefaults standardUserDefaults]
  72. #define kNotificationCenter [NSNotificationCenter defaultCenter]
  73. #define kFileManager ([NSFileManager defaultManager])
  74. #define kAppDelegate ((AppDelegate *)[[UIApplication sharedApplication] delegate])
  75. //-------------- 单例-----------------
  76. #undef AS_SINGLETON
  77. #define AS_SINGLETON( __class ) \
  78. + (__class *)sharedInstance;
  79. #undef DEF_SINGLETON
  80. #define DEF_SINGLETON( __class ) \
  81. + (__class *)sharedInstance \
  82. { \
  83. static dispatch_once_t once; \
  84. static __class * __singleton__; \
  85. dispatch_once( &once, ^{ __singleton__ = [[__class alloc] init]; } ); \
  86. return __singleton__; \
  87. }
  88. //-------------- 单例-----------------
  89. //图片
  90. #define DD_MESSAGE_IMAGE_PREFIX @"&$#@~^@[{:"
  91. #define DD_MESSAGE_IMAGE_SUFFIX @":}]&$~@#@"
  92. // url phone email 正则
  93. #define URL_REGULA @"((?:(http|https|Http|Https|rtsp|Rtsp):\\/\\/(?:(?:[a-zA-Z0-9\\$\\-\\_\\.\\+\\!\\*\\'\\(\\)\\,\\;\\?\\&\\=]|(?:\\%[a-fA-F0-9]{2})){1,64}(?:\\:(?:[a-zA-Z0-9\\$\\-\\_\\.\\+\\!\\*\\'\\(\\)\\,\\;\\?\\&\\=]|(?:\\%[a-fA-F0-9]{2})){1,25})?\\@)?)?((?:(?:[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}\\.)+(?:(?:aero|arpa|asia|a[cdefgilmnoqrstuwxz])|(?:biz|b[abdefghijmnorstvwyz])|(?:cat|com|coop|c[acdfghiklmnoruvxyz])|d[ejkmoz]|(?:edu|e[cegrstu])|f[ijkmor]|(?:gov|g[abdefghilmnpqrstuwy])|h[kmnrtu]|(?:info|int|i[delmnoqrst])|(?:jobs|j[emop])|k[eghimnrwyz]|l[abcikrstuvy]|(?:mil|mobi|museum|m[acdghklmnopqrstuvwxyz])|(?:name|net|n[acefgilopruz])|(?:org|om)|(?:pro|p[aefghklmnrstwy])|qa|r[eouw]|s[abcdeghijklmnortuvyz]|(?:tel|travel|t[cdfghjklmnoprtvwz])|u[agkmsyz]|v[aceginu]|w[fs]|y[etu]|z[amw]))|(?:(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9])\\.(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9]|0)\\.(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9]|0)\\.(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[0-9])))(?:\\:\\d{1,5})?)(\\/(?:(?:[a-zA-Z0-9\\;\\/\\?\\:\\@\\&\\=\\#\\~\\-\\.\\+\\!\\*\\'\\(\\)\\,\\_])|(?:\\%[a-fA-F0-9]{2}))*)?(?:\\b|$)"
  94. #define PHONE_REGULA @"\\d{3}-\\d{8}|\\d{3}-\\d{7}|\\d{4}-\\d{8}|\\d{4}-\\d{7}|1+[358]+\\d{9}|\\d{8}|\\d{7}"
  95. #define EMAIL_REGULA @"[A-Z0-9a-z\\._%+-]+@([A-Za-z0-9-]+\\.)+[A-Za-z]{2,4}"
  96. #define LINK_SPLIT @"!@#$~link~#$@!"
  97. #define NICK_SPLIT @"!@#$~nick~#$@!"
  98. #define PHONE_SPLIT @"!@#$~phone~#$@!"
  99. #define EMAIL_SPLIT @"!@#$~email~#$@!"
  100. #define RGBA(r,g,b,a) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]
  101. #define RGB(r,g,b) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1.0]
  102. #define RDSNavBarColor RGB(248,248,250)
  103. #define RDSViewBgColor RGB(248,248,250)
  104. #define RDSGreenColor RGB(20, 201, 201) // 绿色
  105. #define RDSLightGreenColor RGB(240, 245, 246) // 浅绿色
  106. #define RDSRedColor RGB(228,31,39) // 红色
  107. #define RDSThemeColor RGB(6,40,75) // 深空蓝
  108. #define RDSPinkColor RGB(204, 55, 241) // 粉红色
  109. #define RDSBlueColor RGB(47, 149, 250) // 蓝色
  110. #define RDSHeaderBgColor RGB(214, 214, 215)
  111. #define RDSGrayColor RGB(130, 148, 165) // 灰色
  112. #define RDSLightGrayColor RGB(239, 239, 239) // 浅灰色
  113. #define RDSBlackColor RGB(39, 46, 59) // 黑色
  114. // 字体颜色
  115. #define kTextColor RGB(85,85,85)
  116. #define kDarkTextColor RGBA(6, 40, 75, 1)
  117. //快速定义一个weakSelf 用于block
  118. #define RDS_WEAKSELF(weakSelf) __weak __typeof(&*self)weakSelf = self;
  119. #define BLOCK_SAFE_RUN(block, ...) block != nil ? block(__VA_ARGS__) : nil;
  120. #pragma mark - 全局常量参数
  121. #pragma mark - 通知
  122. extern NSString * const RDSDeviceCmdContentParserNotice;
  123. /// 用户信息更新通知
  124. extern NSString * const RDSUpdateUserInfoNotice;