UI_Formatter&Function.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125,2436), [[UIScreen mainScreen] currentMode].size) : NO)
  15. #pragma mark QiNiu_IMSDK
  16. #define kScreenWidth [[UIScreen mainScreen] bounds].size.width
  17. #define kScreenHeight [[UIScreen mainScreen] bounds].size.height
  18. #define kMainCellColor [UIColor colorWithRed:248/255.0 green:248/255.0 blue:255/255.0 alpha:1]
  19. #define kInputViewHeight 50
  20. #pragma mark - UI宏
  21. #define kStatusHeight (kSize.height == 812.0 ? 44 : 20)
  22. #define kNavOffSet (kSize.height == 812.0 ? 88 : 64)
  23. #define kTabBarHeight (kSize.height == 812.0 ? 83 : 49)
  24. #define SafeAreaBottomHeight (kSize.height == 812.0 ? 34 : 0)
  25. #define kSegmentHeight 44
  26. #define kSize [[UIScreen mainScreen]bounds].size
  27. #ifndef kFrame
  28. #define kFrame [[UIScreen mainScreen]bounds]
  29. #endif
  30. //colors
  31. #define defGreen [UIColor colorWithRed:35/255.0 green:160/255.0 blue:227/255.0 alpha:1]
  32. #define KBackGroundColor [UIColor colorWithRed:247/255.0 green:247/255.0 blue:247/255.0 alpha:1]
  33. #define windowBlockColor [UIColor colorWithWhite:.2 alpha:.2]
  34. #define kLineColor [UIColor colorWithWhite:.3 alpha:.1]
  35. #define KTitleColor [UIColor colorWithRed:70/255.0 green:70/255.0 blue:70/255.0 alpha:1]
  36. #define KSubTitleColor [UIColor colorWithWhite:.3 alpha:1]
  37. #define KContentTextColor [UIColor colorWithRed:110/255.0 green:110/255.0 blue:110/255.0 alpha:1]
  38. #define RGBA_COLOR(R, G, B, A) [UIColor colorWithRed:((R) / 255.0f) green:((G) / 255.0f) blue:((B) / 255.0f) alpha:A]
  39. #define RGB_COLOR(R, G, B) [UIColor colorWithRed:((R) / 255.0f) green:((G) / 255.0f) blue:((B) / 255.0f) alpha:1.0f]
  40. //简单setFrame
  41. #define KSetxywh initWithFrame:CGRectMake(x, y, w, h)
  42. #define KSetDIYFrame CGRectMake(x, y, w, h)
  43. //字体
  44. #define largeFont [UIFont scaleSize:20 weight:10]
  45. #define midFont [UIFont scaleSize:14 weight:5]
  46. #define smallFont [UIFont scaleSize:10 weight:4]
  47. #define Font21 21
  48. #define Font18 18
  49. #define Font17 17
  50. #define Font16 16
  51. #define Font14 14
  52. #define Font10 10
  53. @interface UI_Formatter_Function : NSObject
  54. @end
  55. #pragma mark 字体
  56. @interface UIFont(scale)
  57. /**以414为基准。屏幕越小,字体越小
  58. */
  59. +(id)scaleSize:(CGFloat)font;
  60. @end
  61. #pragma NSNumber 转字符串
  62. @interface NSNumber (formatter)
  63. + (NSString *)stringValue;
  64. @end
  65. #pragma mark UIButton
  66. @interface UIButton(formatter)
  67. - (void) setImage:(UIImage *)image withTitle:(NSString *)title textColor:(UIColor*)color Font:(CGFloat)font forState:(UIControlState)stateType;
  68. -(void) setTitle:(NSString*)title textColor:(UIColor*)color font:(CGFloat)font fotState:(UIControlState)stateType;
  69. /**简化按钮事件添加 要实现btnClick;
  70. */
  71. -(void)target:(id)obj;
  72. -(void)target:(id)obj Tag:(NSInteger)tag;
  73. -(void)setTitleNormal:(NSString*)title;
  74. -(void)setTitleSelect:(NSString*)title;
  75. @end
  76. #pragma mark UILabel
  77. @interface UILabel(formatter)
  78. -(void)setFont:(CGFloat)font TextColor:(UIColor*)color;
  79. -(void)setText:(NSString*)text Font:(CGFloat)font TextColor:(UIColor*)color;
  80. -(void)setText:(NSString*)text Font:(CGFloat)font TextColor:(UIColor*)color Alignment:(NSTextAlignment)align;
  81. @end
  82. #pragma mark UIImageView
  83. @interface UIImageView(formatter)
  84. /**等比缩小 适应imgV大小 裁剪超出部分
  85. */
  86. - (void)setModeAspectFill;
  87. @end
  88. #pragma mark UIImage
  89. @interface UIImage(formatter)
  90. - (UIImage*)scaledToWid:(CGFloat)wid;
  91. - (UIImage*)originImageScaleToSize:(CGSize)size;
  92. - (UIImage*)tint:(UIColor*)color;
  93. /**生成新尺寸 不裁剪图片
  94. */
  95. - (UIImage *)scaledToSize:(CGSize)newSize;
  96. /**生成新尺寸 裁剪图片
  97. */
  98. - (UIImage *)scaledAndCutToSize:(CGSize)newSize;
  99. @end
  100. #pragma mark NSString
  101. #import <CommonCrypto/CommonDigest.h>
  102. @interface NSString (ex)
  103. //MD5 加密
  104. - (NSString *)md5Encrypt;
  105. /**把分钟数转化为 0小时0分钟 格式
  106. */
  107. -(NSString*)hourAndmm;
  108. /**固定宽度,和字体大小。返回高度
  109. */
  110. -(CGFloat)heightForWid:(CGFloat)wid Font:(CGFloat)fontSize;
  111. /** 返回一行文字宽度
  112. */
  113. -(CGFloat)widthForFont:(CGFloat)fontSize;
  114. -(CGSize)sizeForFont:(CGFloat)fontSize;
  115. @end
  116. @interface NSDictionary (Log)
  117. @end
  118. #pragma mark NSArray
  119. @interface NSArray (formatter)
  120. - (id)h_safeObjectAtIndex:(NSUInteger)index;
  121. @end
  122. @interface UIViewController(Navigation)
  123. /**navPush隐藏底部导航栏
  124. */
  125. -(void)navPushHideTabbarToVC:(UIViewController*)vc;
  126. /**pop回去 通过导航栏返回上级菜单
  127. */
  128. -(void)goBackByNavigation;
  129. //回到导航控制器的首页
  130. -(void)goBackFirstVCByNavigation;
  131. /**把nav给Dismiss掉
  132. */
  133. -(void)goBackByNavDismiss;
  134. /**返回直接跳转到rootVC
  135. */
  136. -(void)configNavigationBarPopRoot;
  137. @end