UIFormatter.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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+resize.h"
  11. #import "UIButton+formatter.h"
  12. #import "UIView+Frame.h"
  13. #pragma mark - UI宏
  14. //判断是否是ipad
  15. #define RQ_isPad ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
  16. //判断iPhone4系列
  17. #define kiPhone4 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) && !RQ_isPad : NO)
  18. //判断iPhone5系列
  19. #define kiPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) && !RQ_isPad : NO)
  20. //判断iPhone6系列
  21. #define kiPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) && !RQ_isPad : NO)
  22. //判断iphone6+系列
  23. #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)
  24. //判断iPhoneX
  25. #define IS_IPHONE_X ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) && !RQ_isPad : NO)
  26. //判断iPHoneXr
  27. #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)
  28. //判断iPhoneXs
  29. #define IS_IPHONE_Xs ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) && !RQ_isPad : NO)
  30. //判断iPhoneXs Max
  31. #define IS_IPHONE_Xs_Max ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2688), [[UIScreen mainScreen] currentMode].size) && !RQ_isPad : NO)
  32. //判断iPhone12_Mini
  33. #define IS_IPHONE_iPhone12_Mini ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1080, 2340), [[UIScreen mainScreen] currentMode].size) && !RQ_isPad : NO)
  34. //判断iPhone12 | 12Pro
  35. #define IS_IPHONE_iPhone12 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1170, 2532), [[UIScreen mainScreen] currentMode].size) && !RQ_isPad : NO)
  36. //判断iPhone12 Pro Max
  37. #define IS_IPHONE_iPhone12_ProMax ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1284, 2778), [[UIScreen mainScreen] currentMode].size) && !RQ_isPad : NO)
  38. //x系列
  39. #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)
  40. #define kSegmentHeight 44
  41. #define kTabBarHeight (IS_IPHONE_IPhoneX_All ? 83.0 : 49.0)
  42. #define kStatusHeight (IS_IPHONE_IPhoneX_All ? 44.0 : 20.0)
  43. #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)
  44. #define kSafeAreaBottomHeight (IS_IPHONE_IPhoneX_All ? 34 : 0)
  45. #define kSize [[UIScreen mainScreen]bounds].size
  46. #ifndef kFrame
  47. #define kFrame [[UIScreen mainScreen]bounds]
  48. #endif
  49. //colors
  50. #define newBackGroundColor [UIColor colorWithRed:75/255.0 green:85/255.0 blue:132/255.0 alpha:1]
  51. #define newTitleColor [UIColor colorWithRed:247/255.0 green:247/255.0 blue:247/255.0 alpha:1]
  52. #define newSubTitleColor [UIColor colorWithRed:200/255.0 green:200/255.0 blue:200/255.0 alpha:1]
  53. #define newContentTextColor [UIColor colorWithRed:150/255.0 green:150/255.0 blue:150/255.0 alpha:1]
  54. #define canClickColor [UIColor colorWithRed:134/255.0 green:204/255.0 blue:71/255.0 alpha:1]
  55. #define defGreen [UIColor colorWithRed:253/255.0 green:137/255.0 blue:38/255.0 alpha:1]
  56. #define backGroundColor [UIColor colorWithRed:247/255.0 green:247/255.0 blue:247/255.0 alpha:1]
  57. #define stateBarColor [UIColor colorWithRed:22/255.0 green:90/255.0 blue:140/255.0 alpha:1]
  58. #define windowBlockColor [UIColor colorWithWhite:.2 alpha:.2]
  59. #define lineColor [UIColor colorWithWhite:.3 alpha:.1]
  60. #define kTitleColor [UIColor colorWithRed:70/255.0 green:70/255.0 blue:70/255.0 alpha:1]
  61. #define subTitleColor [UIColor colorWithWhite:.3 alpha:1]
  62. #define contentTextColor [UIColor colorWithRed:110/255.0 green:110/255.0 blue:110/255.0 alpha:1]
  63. #define RGBA_COLOR(R, G, B, A) [UIColor colorWithRed:((R) / 255.0f) green:((G) / 255.0f) blue:((B) / 255.0f) alpha:A]
  64. #define RGB_COLOR(R, G, B) [UIColor colorWithRed:((R) / 255.0f) green:((G) / 255.0f) blue:((B) / 255.0f) alpha:1.0f]
  65. //简单setFrame
  66. #define setxywh initWithFrame:CGRectMake(x, y, w, h)
  67. #define setDIYFrame CGRectMake(x, y, w, h)
  68. //字体
  69. #define largeFont [UIFont scaleSize:20 weight:10]
  70. #define midFont [UIFont scaleSize:14 weight:5]
  71. #define smallFont [UIFont scaleSize:10 weight:4]
  72. #define Font21 21
  73. #define Font18 18
  74. #define Font17 17
  75. #define Font16 16
  76. #define Font14 14
  77. #define Font10 10
  78. #define unOpenMsg @"暂未开放,敬请期待"
  79. /**自动屏幕适配,把屏幕当成320*480来写就行 该方法不适用于动画
  80. */
  81. CGRect SGRectMake(CGFloat x, CGFloat y,CGFloat width,CGFloat height);
  82. /**自动屏幕适配基础上,固定frame的height不进行适配
  83. */
  84. CGRect SGRectMakeCH(CGFloat x, CGFloat y,CGFloat width,CGFloat height);
  85. /**自动屏幕适配基础上,固定frame的y不进行适配
  86. */
  87. CGRect SGRectMakeCY(CGFloat x, CGFloat y,CGFloat width,CGFloat height);
  88. /**自动屏幕适配基础上,固定frame的y,heigh不进行适配
  89. */
  90. CGRect SGRectMakeCYH(CGFloat x, CGFloat y,CGFloat width,CGFloat height);
  91. CGSize SGSizeMake(CGFloat width,CGFloat height);
  92. /**自动屏幕适配的竖向float
  93. */
  94. CGFloat SGFloat(CGFloat k);
  95. @interface UIFormatter : NSObject
  96. @end
  97. //@interface UIViewController(Navigation)
  98. ///**通用导航栏,设置好leftBBI,及其事件
  99. // */
  100. //
  101. ///**通过导航栏返回上级菜单
  102. // */
  103. //-(void)configNavigationBar;
  104. //
  105. ////回到导航控制器的首页
  106. //-(void)configNavigationBarFirstVC;
  107. //
  108. //
  109. ///**隐藏导航栏
  110. // */
  111. //-(void)navPushHideTabbarToVC:(UIViewController*)vc;
  112. ///**这个是隐藏返回按钮的.主要是给搜教练VC用的。因为,它要禁止返回。
  113. // */
  114. //-(void)configNavigationBarHideLeft;
  115. ///**返回直接跳转到rootVC
  116. // */
  117. //-(void)configNavigationBarPopRoot;
  118. //
  119. //@end
  120. @interface UIView(formatter)
  121. -(void)setRound;
  122. -(void)setBoardWid:(CGFloat)width Color:(UIColor*)color;
  123. /**注意:这个headerView是添加到self的superview里面去的。
  124. */
  125. -(void)addViewWithRect:(CGRect)re Color:(UIColor*)color;
  126. -(void)addViewWithRect:(CGRect)re;
  127. /**这个是加到self。
  128. */
  129. -(void)addSelfViewWithRect:(CGRect)re Color:(UIColor*)color;
  130. -(void)scale:(CGFloat)rate;
  131. @end
  132. @interface UIImage (Extension)
  133. /**生成的图片的rect默认为100,100
  134. */
  135. + (UIImage *)imageWithColor:(UIColor *)color;
  136. @end
  137. @interface UIImage(tint)
  138. -(UIImage*)tint:(UIColor*)color;
  139. @end
  140. @interface UIImage (scale)
  141. -(UIImage*)originImageScaleToSize:(CGSize)size;
  142. @end
  143. @interface UIFont(scale)
  144. /**以6plus为基准。屏幕越小,字体越小
  145. */
  146. +(id)scaleSize:(CGFloat)font;
  147. @end
  148. @interface UILabel(formatter)
  149. -(void)setFont:(CGFloat)font TextColor:(UIColor*)color;
  150. -(void)setText:(NSString*)text Font:(CGFloat)font TextColor:(UIColor*)color;
  151. -(void)setText:(NSString*)text Font:(CGFloat)font TextColor:(UIColor*)color Alignment:(NSTextAlignment)align;
  152. @end
  153. UIImage* randomPortrait();
  154. UIColor * randomColor();
  155. void setRandomColor(UIView* vi);