RAUtils.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //
  2. // RAUtils.h
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 9/17/15.
  6. // Copyright (c) 2015 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. #import <UIKit/UIKit.h>
  10. #import "MessageBox.h"
  11. //typedef struct {
  12. //
  13. // NSString* id;
  14. //
  15. // float height;
  16. //
  17. //
  18. //}MyTestStruct;
  19. #define DEBUGLOG
  20. #ifdef DEBUGLOG
  21. #ifdef DEBUG
  22. // #define DebugLog( s, ... ) fprintf(stderr,"%s\n",[[NSString stringWithFormat:s, ##__VA_ARGS__] UTF8String])//
  23. #define DebugLog( s, ... ) fprintf(stderr, "<%p %s:(%d)> %s \n", self, [[[NSString stringWithUTF8String:__FILE__] lastPathComponent]UTF8String], __LINE__, [[NSString stringWithFormat:(s), ##__VA_ARGS__]UTF8String] )
  24. #define blockDebugLog( s, ... ) fprintf(stderr, "<%p %s:(%d)> %s \n",weakself, [[[NSString stringWithUTF8String:__FILE__] lastPathComponent]UTF8String], __LINE__, [[NSString stringWithFormat:(s), ##__VA_ARGS__]UTF8String] )
  25. #else
  26. #define DebugLog( s, ... )
  27. #define blockDebugLog( s, ... )
  28. #endif
  29. #else
  30. #define DebugLog( s, ... )
  31. #define blockDebugLog( s, ... )
  32. #endif
  33. NS_ASSUME_NONNULL_BEGIN
  34. @interface RAUtils : NSObject
  35. + (CGSize)sizeWithFont:(NSString*_Nonnull)string font:(UIFont *_Nonnull)font constrainedToSize:(CGSize)size lineBreakMode:(NSLineBreakMode)lineBreakMode;
  36. + (BOOL)isNumeric:(NSString*)string;
  37. //+(NSData*) dict2data:(NSDictionary*) dict;
  38. +(NSString*) FloatFormat:(float)value;
  39. +(UIViewController*) getViewController:(UIView*) view;
  40. + (CGRect)relativeFrameForScreenWithView:(UIView *)v;
  41. +(NSDictionary*) error_json :(int)code err_msg:(NSString* _Nullable)msg;
  42. //+(UIAlertController*) message_alert :(NSString* _Nullable) msg title:(NSString*_Nullable) title controller:(UIViewController*) vc;
  43. //+(UIAlertController*) message_alert :(NSString*) msg title:(NSString*) title controller:(UIViewController*) vc action_handler:(void (^ __nullable)(UIAlertAction *action))action_handler completion:(void (^ __nullable)(void))completion;
  44. //+(UIAlertController*) waiting_alert:(UIViewController*)parent title:(NSString*) title completion:(void (^ __nullable)(void))completion;
  45. //+(UIAlertController*) waiting_alert:(UIViewController*)parent message:(NSString*)msg title:(NSString*) title completion:(void (^ __nullable)(void))completion;
  46. + (float)fileSizeForDir:(NSString*)path;//计算文件夹下文件的总大小;
  47. +(void) deletefiles :(NSString*) path;
  48. +(UIColor*) strColor:(NSString*) color;
  49. +(NSString*) get_config_path;
  50. +(NSString*) base64en:(NSString*) string;
  51. +(NSString*) base64de:(NSString*) string;
  52. +(NSDictionary*) device_info;
  53. +(NSDictionary*) error_dict:(NSError*)error;
  54. + (NSArray*) allFilesAtPath:(NSString*) dirString;
  55. //+(void) enum_font;
  56. +(NSDictionary*) dictfromfile:(NSString*) path;
  57. +(void) dicttofile:(NSString*) path dict:(NSDictionary*)dict;
  58. //+(NSArray*) expression_varable:(NSString*)content regex:(NSString*) pattern;
  59. //+(NSTextCheckingResult*) expression_findfistMatch:(NSString*)content regex:(NSString*) pattern;
  60. +(NSData*) getdbfile:(NSString*)dbname;
  61. // 2020-1118 去掉zip 如果以后需要用到,单独加在其他包内
  62. //+(NSString*) getdbzip:(NSString*)dbname;
  63. + (UIImage *)scaleToSize:(UIImage *)img size:(CGSize)size;
  64. + (CGRect)scaleToSize:(CGRect )from to:(CGSize)to;
  65. + (CGRect)rectAlign:(CGRect )parent rect:(CGRect)rect hAlign:(NSString*)hAlign vAlign:(NSString*)vAlign;
  66. + (CGRect)rectVAlign:(CGRect )parent rect:(CGRect)rect vAlign:(NSString*)vAlign;
  67. +(UIImage*)img_compress:(UIImage*)image kbsize:(float) size;
  68. +(NSString* )current_date;
  69. +(NSString*) current_date_time;
  70. +(NSString*) current_date_forfile;
  71. +(NSMutableArray*)dictionary2array:(NSDictionary*)json count_fields:(NSString*) count_fields item_mark:(NSString*) item_mark items_mark:(NSString* _Nullable )items_mark;
  72. +(int)getRandomNumber:(int)from to:(int)to;
  73. //+(void) add_recent_model:(NSDictionary*) model;
  74. + (long long) freeDiskSpaceInMegaBytes;
  75. //+(NSArray*) string2arr:(NSString*) string separator:(NSString*)separator;
  76. + (UIWindow *)keyWindow;
  77. + (bool)mergeContentsOfPath:(NSString *)srcDir intoPath:(NSString *)dstDir error:(NSError**)err;
  78. + (BOOL)saveData:(NSData *)data toPath:(NSString *)path;
  79. + (void)removeFileAtPath:(NSString *)path;
  80. + (NSString *)appCacheDirectory;
  81. +(NSString*)md5WithFile:(NSString*)path;
  82. + (BOOL)fileExistsAtPath:(NSString *)path;
  83. + (NSString *)htmlForVideo:(NSString*) iframeCode template:(NSString*) path;
  84. + (NSString *)htmlForImage:(UIImage *)image template:(NSString*) path;
  85. + (CGRect)relativeFrame:(CGRect) frame FromView:(UIView *)v toView:(UIView*)tv;
  86. + (nullable NSString *)md5:(nullable NSString *)str;
  87. + (NSString *_Nullable)deviceID;
  88. + (void)ra_showAlertTitle:(NSString *_Nullable)title message:(NSString *_Nullable)msg withViewController:(UIViewController *_Nonnull)vc;
  89. + (BOOL) validateEmail:(NSString *)email;
  90. + (BOOL)checkPassword:(NSString *) password;
  91. + (UIViewController *)getCurrentVCFrom:(UIViewController *)rootVC;
  92. + (UIViewController *)getCurrentVC;
  93. +(NSDictionary* )copyDict:(NSDictionary* ) source;
  94. +(void) playSound:(NSString*) name type:(NSString*) type;
  95. +(UIInterfaceOrientation)query_orientation:(UIViewController*)vc;
  96. +(PopWaitAlert*) waiting_pop:(nullable NSString*) title completion:(void (^ __nullable)(void))completion;
  97. +(MessageBox*) message_box:(nullable NSString*) title message:(nullable NSString*)message completion:(void (^ __nullable)(void))completion;
  98. @end
  99. NS_ASSUME_NONNULL_END