MOTools.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. //
  2. // MOTools.h
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2023/10/9.
  6. //
  7. #import <Foundation/Foundation.h>
  8. NS_ASSUME_NONNULL_BEGIN
  9. @interface MOTools : NSObject
  10. @property (nonatomic, assign) NSInteger seed;
  11. //16进制颜色转换
  12. + (UIColor *)colorWithHexString:(NSString *)hexString;
  13. + (UIColor *)colorWithHexString:(NSString *)hexString alpha:(CGFloat)alpha;
  14. ///计算文字高度
  15. + (CGFloat)calculateRowHeight:(NSString *)string fontSize:(NSInteger)fontSize andWidth:(CGFloat)width;
  16. ///计算文字高度
  17. + (CGFloat)calculateRowHeight:(NSString *)string font:(UIFont *)font andWidth:(CGFloat)width;
  18. /// 计算文字高度 无行间距
  19. + (CGFloat)calculateRowHeightNoLine:(NSString *)string font:(UIFont *)font andWidth:(CGFloat)width;
  20. /// 计算文字高度 无行间距版 (注意跟上个方法做区分)
  21. + (CGFloat)calculateRowHeightNoLineSpacing:(NSString *)string fontSize:(NSInteger)fontSize andWidth:(CGFloat)width;
  22. /// 计算文字长度
  23. /// @param string 文字
  24. /// @param font 字号
  25. + (CGFloat)getWidthWithString:(NSString *)string font:(UIFont *)font;
  26. //获取文字的尺寸
  27. + (CGSize)getSizeFrom:(NSString *)content font:(UIFont *)font maxSize:(CGSize)maxSize;
  28. /// 根据颜色生成一张图片
  29. /// @param color 颜色
  30. + (UIImage*)createImageWithColor:(UIColor*)color;
  31. /**
  32. * 绘制渐变色的矩形UIImage
  33. *
  34. * @param bounds UIImage的bounds
  35. * @param colors 渐变色数组,可以设置两种颜色
  36. * @param gradientType 渐变的方式:0:水平渐变 1:竖直渐变 2:向下对角线渐变 3:向上对角线渐变
  37. *
  38. * @return 渐变色的UIImage
  39. */
  40. + (UIImage*)createGradientRectImageWithBounds:(CGRect)bounds
  41. Colors:(NSArray*)colors
  42. GradientType:(int)gradientType;
  43. /// 将数组中的字符串按照拼音排序(先比较第一个汉字,然后比较第二个汉字,并且第一个汉字按照音标排序,非汉字排在后面,胥<徐<许<x<xu,许1<许3<许21,3502<123456)
  44. /// @param oldArray 需要排序的数组,每个元素都必须是同一种类型
  45. /// @param keyPath 如果oldArray的数组元素不是NSString类型,则[元素 valueForKey:keyPath]必须是字符串类型
  46. + (NSArray *)sortArrayByPinYin:(NSArray *)oldArray objectTextKeyPath:(NSString *)keyPath;
  47. //获取设备信息
  48. + (NSDictionary *)getDeviceInfo;
  49. //获取设备字符串
  50. + (NSString *)getDeviceString;
  51. ///获取设备类型
  52. + (NSString *)getCurrentDeviceModel;
  53. /// 将传入的数字进行模式化 - (1345 -> 1000)
  54. /// - Parameter number: 参数
  55. + (NSInteger)keepFirstDigitAndZeroOthersWith:(double)number;
  56. /// 将传入的数字进行模式化 - (大于1W -> 10000 , 小于1W大于1000, 则为1000, 如果小于1000则为具体数字)
  57. + (NSInteger)keepFirstZeroOthersWith:(double)number;
  58. /// 设置这一次弹出手机绑定弹窗设备的时间
  59. + (void)setTimeOfShowBindDevice:(NSDate *)time;
  60. /// 获取上一次手机绑定弹窗的时间
  61. + (NSDate *)getTimeOfShowBind;
  62. /// 是否时间过了一天
  63. + (BOOL)shouldShowAlertWithLastTime:(NSDate *)lastTime;
  64. /// 设置签到时间 - 根据用户ID
  65. + (void)setTimeOfShowSignDevice:(NSDate *)time;
  66. /// 获取上一次签到时间 */
  67. + (NSDate *)getTimeOfShowSign;
  68. - (NSInteger)mo_nextDoubleAndMin:(NSInteger)min And:(NSInteger)max;
  69. + (UIViewController *)currentViewController;
  70. /// 更新服务器时间的差值
  71. + (void)toUpdataTheRedSysTimeWith:(int64_t)sysTime;
  72. + (UIView *)containsViewOfClass:(Class)viewClass inView:(UIView *)view;
  73. + (BOOL)toJudgeShowWame;
  74. /// 获取并本地存储图片
  75. + (void)fetchAndStoreImageWithUrl:(NSString *)url completeBlock:(void (^)(UIImage *image))completeBlock;
  76. /// 邮箱判断正则
  77. + (BOOL)isValidEmail:(NSString *)email;
  78. /// 手机号字符串**替换
  79. + (NSString *)maskPhoneNumber:(NSString *)phoneNumber;
  80. + (NSString *)getValueWithKey:(NSString *)key urlString:(NSString *)urlString;
  81. + (NSString *)getValueWithKey:(NSString *)key url:(NSURL *)url;
  82. //字典转json格式字符串:
  83. + (NSString *)dictionaryToJson:(NSDictionary *)dic;
  84. //json格式字符串转字典:
  85. + (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString;
  86. //根据VIP 类型 和 尺寸 生成对应的图片
  87. + (UIImage *)getVipImgIconWith:(NSInteger)type AndSize:(CGSize)size;
  88. //根据道具分类, 拿分类图片
  89. + (UIImage *)toGetThePropsTypeWith:(NSInteger)type;
  90. /// 退出键盘
  91. + (void)dismissKeyboard;
  92. //判断两个字符串数组 是否一样
  93. + (BOOL)isStringArrayContentEqualIgnoringOrder:(NSArray<NSString *> *)array1 array2:(NSArray<NSString *> *)array2;
  94. ///去生成一个随机ID
  95. + (NSString *)generateUniqueID;
  96. /// 超出指定长度替换成...
  97. /// - Parameters:
  98. /// - string: 字符串
  99. /// - maxLength: 最大长度
  100. + (NSString *)trimString:(NSString *)string maxLength:(NSInteger)maxLength;
  101. ///时间戳转几分钟前
  102. + (NSString *)timeAgoStringFromTimeStamp:(NSTimeInterval)timeStamp;
  103. @end
  104. NS_ASSUME_NONNULL_END