UIFormatter.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. //
  2. // UIFormatter.h
  3. // test11
  4. //
  5. // Created by apple on 15/11/13.
  6. // Copyright (c) 2016年 JCZ. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. #import <UIKit/UIKit.h>
  10. /**
  11. 这里貌似有2个高度。1种是屏幕高度。1种是被导航栏偏移减少后的高度
  12. */
  13. #define kSize [[UIScreen mainScreen]bounds].size
  14. #ifndef kFrame
  15. #define kFrame [[UIScreen mainScreen]bounds]
  16. #endif
  17. #pragma mark - UI宏
  18. //判断是否是ipad
  19. #define RQ_isPad ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
  20. //判断iPhone4系列
  21. #define kiPhone4 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) && !RQ_isPad : NO)
  22. //判断iPhone5系列
  23. #define kiPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) && !RQ_isPad : NO)
  24. //判断iPhone6系列
  25. #define kiPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) && !RQ_isPad : NO)
  26. //判断iphone6+系列
  27. #define kiPhone6Plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size) || CGSizeEqualToSize(CGSizeMake(1080, 1920), [[UIScreen mainScreen] currentMode].size) && !RQ_isPad : NO)
  28. //判断iPhoneX
  29. #define IS_IPHONE_X ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) && !RQ_isPad : NO)
  30. //判断iPHoneXr
  31. #define IS_IPHONE_Xr ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? (CGSizeEqualToSize(CGSizeMake(828, 1792), [[UIScreen mainScreen] currentMode].size) || CGSizeEqualToSize(CGSizeMake(750, 1624), [[UIScreen mainScreen] currentMode].size)) && !RQ_isPad : NO)
  32. //判断iPhoneXs
  33. #define IS_IPHONE_Xs ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) && !RQ_isPad : NO)
  34. //判断iPhoneXs Max
  35. #define IS_IPHONE_Xs_Max ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2688), [[UIScreen mainScreen] currentMode].size) && !RQ_isPad : NO)
  36. //判断iPhone12_Mini
  37. #define IS_IPHONE_iPhone12_Mini ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1080, 2340), [[UIScreen mainScreen] currentMode].size) && !RQ_isPad : NO)
  38. //判断iPhone12 | 12Pro
  39. #define IS_IPHONE_iPhone12 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1170, 2532), [[UIScreen mainScreen] currentMode].size) && !RQ_isPad : NO)
  40. //判断iPhone12 Pro Max
  41. #define IS_IPHONE_iPhone12_ProMax ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1284, 2778), [[UIScreen mainScreen] currentMode].size) && !RQ_isPad : NO)
  42. //x系列
  43. #define IS_IPHONE_IPhoneX_All (IS_IPHONE_X || IS_IPHONE_Xr || IS_IPHONE_Xs || IS_IPHONE_Xs_Max || IS_IPHONE_iPhone12_Mini || IS_IPHONE_iPhone12 || IS_IPHONE_iPhone12_ProMax)
  44. #define KScreenSize [UIScreen mainScreen].bounds.size
  45. #define KScreenwidth [UIScreen mainScreen].bounds.size.width
  46. #define KScreenheight [UIScreen mainScreen].bounds.size.height
  47. //#define kFrame [[UIScreen mainScreen]bounds]
  48. //#define kSize [[UIScreen mainScreen]bounds].size
  49. #define kCellBd 1
  50. #define kCellW (kSize.width - 2*kCellBd)/3.0
  51. #define kCellH (kCellW - kCellBd)/2.0
  52. #define kSecHeadHeight 10
  53. //75
  54. #define kNavBarHeight 44
  55. #define kSegmenHeight 51
  56. #define kLeftViewWid kSize.width * 0.87
  57. #define kTabBarHeight (IS_IPHONE_IPhoneX_All ? 83.0 : 49.0)
  58. #define kStatusHeight (IS_IPHONE_IPhoneX_All ? 44.0 : 20.0)
  59. #define kNavOffSet ((IS_IPHONE_Xr == YES || IS_IPHONE_Xs == YES || IS_IPHONE_Xs_Max == YES || IS_IPHONE_iPhone12_Mini == YES) ? 88.0 : (IS_IPHONE_X == YES) ? 92 : (IS_IPHONE_iPhone12 == YES || IS_IPHONE_iPhone12_ProMax == YES) ? 91 : 64.0)
  60. #define kSafeAreaBottomHeight (IS_IPHONE_IPhoneX_All ? 34 : 0)
  61. #define defaultImg [UIImage imageNamed:@"subject2_standart_icon.png"]
  62. #define navBarColor [UIColor colorWithLightColorStr:@"FFFFFF" DarkColor:@"000000"]
  63. #define backGroundColor [UIColor colorWithLightColorStr:@"FFFFFF" DarkColor:@"181818"]
  64. #define selectedBackGroundColor [UIColor colorWithLightColorStr:@"F6F6F6" DarkColor:@"303030"]
  65. #define windowBlockColor [UIColor colorWithWhite:.2 alpha:.2]
  66. #define RQlineColor [UIColor colorWithLightColorStr:@"EFEFF4" DarkColor:@"000000"]
  67. #define kTitleColor [UIColor colorWithLightColorStr:@"464646" DarkColor:@"F7F7F7"]
  68. #define subTitleColor [UIColor colorWithLightColorStr:@"787878" DarkColor:@"F7F7F7"]
  69. #define contentTextColor [UIColor colorWithLightColorStr:@"6E6E6E" DarkColor:@"F7F7F7"]
  70. #define RGBA_COLOR(R, G, B, A) [UIColor colorWithRed:((R) / 255.0f) green:((G) / 255.0f) blue:((B) / 255.0f) alpha:A]
  71. #define RGB_COLOR(R, G, B) [UIColor colorWithRed:((R) / 255.0f) green:((G) / 255.0f) blue:((B) / 255.0f) alpha:1.0f]
  72. //测试服的图片地址
  73. #define imgPreTest @"http://218.6.66.181:9999/doc/"
  74. //正式服的图片地址
  75. #define imgPreFix @"http://fj.jppt.com.cn/doc/"
  76. #define kBgColor 0.95
  77. #define largeFont [UIFont scaleSize:20 weight:10]
  78. #define midFont [UIFont scaleSize:14 weight:5]
  79. #define smallFont [UIFont scaleSize:10 weight:4]
  80. //简单setFrame
  81. #define setxywh initWithFrame:CGRectMake(x, y, w, h)
  82. #define setDIYFrame CGRectMake(x, y, w, h)
  83. #define FontLarger 21
  84. #define FontTitle 18
  85. #define Font17 17
  86. #define Font16 16
  87. #define NormalFont 15
  88. #define Font13 13
  89. #define SmallFont 10
  90. /// 适配iPhone X + iOS 11
  91. #define RQAdjustsScrollViewInsets_Never(__scrollView)\
  92. do {\
  93. _Pragma("clang diagnostic push")\
  94. _Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"")\
  95. if ([__scrollView respondsToSelector:NSSelectorFromString(@"setContentInsetAdjustmentBehavior:")]) {\
  96. NSMethodSignature *signature = [UIScrollView instanceMethodSignatureForSelector:@selector(setContentInsetAdjustmentBehavior:)];\
  97. NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];\
  98. NSInteger argument = 2;\
  99. invocation.target = __scrollView;\
  100. invocation.selector = @selector(setContentInsetAdjustmentBehavior:);\
  101. [invocation setArgument:&argument atIndex:2];\
  102. [invocation retainArguments];\
  103. [invocation invoke];\
  104. }\
  105. _Pragma("clang diagnostic pop")\
  106. } while (0)
  107. #define unOpenMsg @"暂未开放,敬请期待"
  108. /**自动屏幕适配,把屏幕当成320*480来写就行了。
  109. 该方法不适用于动画
  110. */
  111. CGRect SGRectMake(CGFloat x, CGFloat y,CGFloat width,CGFloat height);
  112. /**自动屏幕适配基础上,固定frame的height不进行适配
  113. */
  114. //CGRect SGRectMakeCH(CGFloat x, CGFloat y,CGFloat width,CGFloat height);
  115. /**自动屏幕适配基础上,固定frame的y不进行适配
  116. */
  117. //CGRect SGRectMakeCY(CGFloat x, CGFloat y,CGFloat width,CGFloat height);
  118. /**自动屏幕适配基础上,固定frame的y,heigh不进行适配
  119. */
  120. CGRect SGRectMakeCYH(CGFloat x, CGFloat y,CGFloat width,CGFloat height);
  121. CGSize SGSizeMake(CGFloat width,CGFloat height);
  122. /**自动屏幕适配的竖向float
  123. */
  124. CGFloat SGFloat(CGFloat k);
  125. @interface UIFormatter : NSObject
  126. @end
  127. @interface UIViewController(Navigation)
  128. /**通用导航栏,设置好leftBBI,及其事件
  129. */
  130. -(void)configNavigationBar;
  131. /**通过导航栏返回上级菜单
  132. */
  133. //回到导航控制器的首页
  134. -(void)configNavigationBarFirstVC;
  135. /**
  136. 这个是把nav给Dismiss掉
  137. */
  138. -(void)configNavigationBarDismissNav;
  139. /**隐藏导航栏
  140. */
  141. -(void)navPushHideTabbarToVC:(UIViewController*)vc;
  142. /**这个是隐藏返回按钮的.主要是给搜教练VC用的。因为,它要禁止返回。
  143. */
  144. -(void)configNavigationBarHideLeft;
  145. /**返回直接跳转到rootVC
  146. */
  147. -(void)configNavigationBarPopRoot;
  148. @end
  149. @interface UIView(formatter)
  150. -(void)setRound;
  151. - (void)setBoardWid:(CGFloat)width Color:(UIColor*)color CornerRadius:(NSInteger)cornerRadius;
  152. /**注意:这个headerView是添加到self的superview里面去的。
  153. */
  154. -(void)addViewWithRect:(CGRect)re Color:(UIColor*)color;
  155. -(void)addViewWithRect:(CGRect)re;
  156. /**这个是加到self。
  157. */
  158. -(void)addSelfViewWithRect:(CGRect)re Color:(UIColor*)color;
  159. -(void)scale:(CGFloat)rate;
  160. @end
  161. @interface UIImage (Extension)
  162. /**生成的图片的rect默认为100,100
  163. */
  164. + (UIImage *)imageWithColor:(UIColor *)color;
  165. @end
  166. @interface UIImage(tint)
  167. -(UIImage*)tint:(UIColor*)color;
  168. @end
  169. @interface UIImage (scale)
  170. -(UIImage*)originImageScaleToSize:(CGSize)size;
  171. @end
  172. @interface UIFont(scale)
  173. /**以6plus为基准。屏幕越小,字体越小
  174. */
  175. +(id)scaleSize:(CGFloat)font;
  176. @end
  177. @interface UILabel(formatter)
  178. -(void)setFont:(CGFloat)font TextColor:(UIColor*)color;
  179. -(void)setText:(NSString*)text Font:(CGFloat)font TextColor:(UIColor*)color;
  180. -(void)setText:(NSString*)text Font:(CGFloat)font TextColor:(UIColor*)color Alignment:(NSTextAlignment)align;
  181. @end
  182. UIImage* randomPortrait(void);
  183. UIColor * randomColor(void);
  184. void setRandomColor(UIView* vi);