UIFormatter.h 9.1 KB

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