UI_Formatter&Function.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. //
  2. // UI_Formatter&Function.h
  3. // LN_School
  4. //
  5. // Created by apple on 2017/4/5.
  6. // Copyright © 2017年 Danson. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. #import <UIKit/UIKit.h>
  10. //版本判定
  11. #define iOS8 ([UIDevice currentDevice].systemVersion.floatValue >= 8.0f)
  12. #define iOS10 ([UIDevice currentDevice].systemVersion.floatValue >= 10.0f)
  13. #define IOS11 @available(iOS 11.0, *)
  14. #define kDevice_Is_iPhoneX [Tools isIPhoneX]
  15. //#define kDevice_Is_iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125,2436), [[UIScreen mainScreen] currentMode].size) : NO)
  16. #pragma mark QiNiu_IMSDK
  17. #define kScreenWidth [[UIScreen mainScreen] bounds].size.width
  18. //#define kScreenHeight [[UIScreen mainScreen] bounds].size.height
  19. #define kMainCellColor [UIColor colorWithRed:248/255.0 green:248/255.0 blue:255/255.0 alpha:1]
  20. #define kInputViewHeight 50
  21. #pragma mark - UI宏
  22. //判断是否是ipad
  23. #define kIsPad ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
  24. //判断iPhone4系列
  25. #define kiPhone4 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) && !kIsPad : NO)
  26. //判断iPhone5系列
  27. #define kiPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) && !kIsPad : NO)
  28. //判断iPhone6系列
  29. #define kiPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) && !kIsPad : NO)
  30. //判断iphone6+系列
  31. #define kiPhone6Plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size) && !kIsPad : NO)
  32. //判断iPhoneX
  33. #define IS_IPHONE_X ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) && !kIsPad : NO)
  34. //判断iPHoneXr
  35. #define IS_IPHONE_Xr ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(828, 1792), [[UIScreen mainScreen] currentMode].size) && !kIsPad : NO)
  36. //判断iPhoneXs
  37. #define IS_IPHONE_Xs ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) && !kIsPad : NO)
  38. //判断iPhoneXs Max
  39. #define IS_IPHONE_Xs_Max ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2688), [[UIScreen mainScreen] currentMode].size) && !kIsPad : NO)
  40. //#define kFrame [[UIScreen mainScreen]bounds]
  41. //#define kSize [[UIScreen mainScreen]bounds].size
  42. #define kCellBd 1
  43. #define kCellW (kSize.width - 2*kCellBd)/3.0
  44. #define kCellH (kCellW - kCellBd)/2.0
  45. #define kSecHeadHeight 10
  46. //75
  47. #define kNavBarHeight 44
  48. #define kSegmenHeight 44
  49. #define kLeftViewWid kSize.width * 0.8
  50. #define kTabBarHeight ((IS_IPHONE_X==YES || IS_IPHONE_Xr ==YES || IS_IPHONE_Xs== YES || IS_IPHONE_Xs_Max== YES) ? 83.0 : 49.0)
  51. #define kStatusHeight ((IS_IPHONE_X==YES || IS_IPHONE_Xr ==YES || IS_IPHONE_Xs== YES || IS_IPHONE_Xs_Max== YES) ? 44.0 : 20.0)
  52. #define kNavOffSet ((IS_IPHONE_X==YES || IS_IPHONE_Xr ==YES || IS_IPHONE_Xs== YES || IS_IPHONE_Xs_Max== YES) ? 88.0 : 64.0)
  53. #define kSafeAreaBottomHeight ((IS_IPHONE_X==YES || IS_IPHONE_Xr ==YES || IS_IPHONE_Xs== YES || IS_IPHONE_Xs_Max== YES) ? 34 : 0)
  54. #define kSize [[UIScreen mainScreen]bounds].size
  55. #ifndef kFrame
  56. #define kFrame [[UIScreen mainScreen]bounds]
  57. #endif
  58. //colors
  59. #define RQMianColor RQColorFromHexString(@"5375c9")
  60. #define RQSubColor RQColorFromHexString(@"3faeff")
  61. #define RQTitleTextColor RQColorFromHexString(@"787878")
  62. #define RQContentTextColor RQColorFromHexString(@"2f2f2f")
  63. #define RQPinkBlueColor RQColorFromHexString(@"5c87f8")
  64. #define RQPinkGreenColor RQColorFromHexString(@"0ab2a0")
  65. #define RQGreenColor RQColorFromHexString(@"00d08a")
  66. #define RQOrangeColor RQColorFromHexString(@"f48f37")
  67. #define RQRedColor RQColorFromHexString(@"f96060")
  68. #define RQBackGroundColor RQColorFromHexString(@"f6f7fb")
  69. #define KBackGroundColor [UIColor colorWithRed:247/255.0 green:247/255.0 blue:247/255.0 alpha:1]
  70. #define windowBlockColor [UIColor colorWithWhite:.2 alpha:.2]
  71. #define kLineColor [UIColor colorWithWhite:.3 alpha:.1]
  72. #define KTitleColor [UIColor colorWithRed:70/255.0 green:70/255.0 blue:70/255.0 alpha:1]
  73. #define KSubTitleColor [UIColor colorWithWhite:.3 alpha:1]
  74. #define KContentTextColor [UIColor colorWithRed:110/255.0 green:110/255.0 blue:110/255.0 alpha:1]
  75. #define RGBA_COLOR(R, G, B, A) [UIColor colorWithRed:((R) / 255.0f) green:((G) / 255.0f) blue:((B) / 255.0f) alpha:A]
  76. #define RGB_COLOR(R, G, B) [UIColor colorWithRed:((R) / 255.0f) green:((G) / 255.0f) blue:((B) / 255.0f) alpha:1.0f]
  77. /// 根据hex 获取颜色
  78. #define RQColorFromHexString(__hexString__) ([UIColor colorFromHexString:__hexString__])
  79. //简单setFrame
  80. #define KSetxywh initWithFrame:CGRectMake(x, y, w, h)
  81. #define KSetDIYFrame CGRectMake(x, y, w, h)
  82. //字体
  83. #define largeFont [UIFont scaleSize:20 weight:10]
  84. #define midFont [UIFont scaleSize:14 weight:5]
  85. #define smallFont [UIFont scaleSize:10 weight:4]
  86. #define Font21 21
  87. #define Font18 18
  88. #define Font17 17
  89. #define Font16 16
  90. #define Font14 14
  91. #define Font10 10
  92. @interface UI_Formatter_Function : NSObject
  93. @end
  94. #pragma mark 字体
  95. @interface UIFont(scale)
  96. /**以414为基准。屏幕越小,字体越小
  97. */
  98. +(id)scaleSize:(CGFloat)font;
  99. @end
  100. #pragma NSNumber 转字符串
  101. @interface NSNumber (formatter)
  102. + (NSString *)stringValue;
  103. @end
  104. #pragma mark UIButton
  105. @interface UIButton(formatter)
  106. - (void) setImage:(UIImage *)image withTitle:(NSString *)title textColor:(UIColor*)color Font:(CGFloat)font forState:(UIControlState)stateType;
  107. -(void) setTitle:(NSString*)title textColor:(UIColor*)color font:(CGFloat)font fotState:(UIControlState)stateType;
  108. /**简化按钮事件添加 要实现btnClick;
  109. */
  110. -(void)target:(id)obj;
  111. -(void)target:(id)obj Tag:(NSInteger)tag;
  112. -(void)setTitleNormal:(NSString*)title;
  113. -(void)setTitleSelect:(NSString*)title;
  114. @end
  115. #pragma mark UILabel
  116. @interface UILabel(formatter)
  117. -(void)setFont:(CGFloat)font TextColor:(UIColor*)color;
  118. -(void)setText:(NSString*)text Font:(CGFloat)font TextColor:(UIColor*)color;
  119. -(void)setText:(NSString*)text Font:(CGFloat)font TextColor:(UIColor*)color Alignment:(NSTextAlignment)align;
  120. @end
  121. #pragma mark UIImageView
  122. @interface UIImageView(formatter)
  123. /**等比缩小 适应imgV大小 裁剪超出部分
  124. */
  125. - (void)setModeAspectFill;
  126. @end
  127. #pragma mark UIImage
  128. @interface UIImage(formatter)
  129. - (UIImage*)scaledToWid:(CGFloat)wid;
  130. - (UIImage*)originImageScaleToSize:(CGSize)size;
  131. - (UIImage*)tint:(UIColor*)color;
  132. /**生成新尺寸 不裁剪图片
  133. */
  134. - (UIImage *)scaledToSize:(CGSize)newSize;
  135. /**生成新尺寸 裁剪图片
  136. */
  137. - (UIImage *)scaledAndCutToSize:(CGSize)newSize;
  138. @end
  139. #pragma mark NSString
  140. #import <CommonCrypto/CommonDigest.h>
  141. @interface NSString (ex)
  142. //MD5 加密
  143. - (NSString *)md5Encrypt;
  144. /**把分钟数转化为 0小时0分钟 格式
  145. */
  146. -(NSString*)hourAndmm;
  147. /**固定宽度,和字体大小。返回高度
  148. */
  149. -(CGFloat)heightForWid:(CGFloat)wid Font:(CGFloat)fontSize;
  150. /** 返回一行文字宽度
  151. */
  152. //-(CGFloat)widthForFont:(CGFloat)fontSize;
  153. -(CGSize)sizeForFont:(CGFloat)fontSize;
  154. @end
  155. #pragma mark NSArray
  156. @interface NSArray (formatter)
  157. - (id)h_safeObjectAtIndex:(NSUInteger)index;
  158. @end
  159. @interface UIViewController(Navigation)
  160. /**navPush隐藏底部导航栏
  161. */
  162. -(void)navPushHideTabbarToVC:(UIViewController*)vc;
  163. /**pop回去 通过导航栏返回上级菜单
  164. */
  165. -(void)goBackByNavigation;
  166. //回到导航控制器的首页
  167. -(void)goBackFirstVCByNavigation;
  168. /**把nav给Dismiss掉
  169. */
  170. -(void)goBackByNavDismiss;
  171. /**返回直接跳转到rootVC
  172. */
  173. -(void)configNavigationBarPopRoot;
  174. @end