IOS 公共类-MyMBProgressUtil Progress显示

时间:2022-07-05 09:37:50

IOS 公共类-MyMBProgressUtil Progress显示

此公共类用于显示提示框,对MBProgress的进一步封装。可以看下面的代码

接口:

 @interface MyMBProgressUtil 

 //显示Progress在view上
+(void) showMBProgressHUDViewInView:(UIView*)view andText:(NSString*)text;
//隐藏Progress在view上
+(void) hiddenMBProgressHUDViewInView:(UIView *)view; //显示Progress在window上
+(void) showMBProgressHUDViewInWindow;
//隐藏Progress在window上
+(void) hiddenMBProgressHUDViewInWindow; //显示文字在view上,默认0.8秒后隐藏
+(void) showTextOnlyWithMBProgressHUDViewIn:(UIView*)view withText:(NSString*)text;
//显示文字在view上,自己设定多少秒后隐藏
+(void) showTextOnlyWithMBProgressHUDViewIn:(UIView*)view withText:(NSString*)text withTimeSeconds:(CGFloat)seconds;
//显示详细文字在view上,自己设定多少秒后隐藏
+(void) showTextOnlyWithMBProgressHUDViewIn:(UIView*)view withDetailText:(NSString*)detailText withTimeSeconds:(CGFloat)seconds; @end

实现类:

 @implementation MyMBProgressUtil: NSObject

 +(void) showMBProgressHUDViewInView:(UIView*)view andText:(NSString*)text {
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
hud.clipsToBounds = NO;
[hud setLabelText:text];
hud.removeFromSuperViewOnHide = YES;
hud.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:0.3f];
CGRect frame = CGRectMake(hud.frame.origin.x, hud.frame.origin.y, hud.frame.size.width-, hud.frame.size.height-);
hud.frame = frame;
} +(void)hiddenMBProgressHUDViewInView:(UIView *)view {
[MBProgressHUD hideHUDForView:view animated:YES];
} +(void) showMBProgressHUDViewInWindow {
UIWindow *win = [UIApplication sharedApplication].keyWindow;
MBProgressHUD *hud = [[MBProgressHUD alloc] initWithWindow:win];
hud.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:0.3f];
hud.mode = MBProgressHUDModeIndeterminate;
hud.removeFromSuperViewOnHide = YES;
[win addSubview:hud];
[hud show:YES];
} +(void) hiddenMBProgressHUDViewInWindow {
UIWindow *win = [UIApplication sharedApplication].keyWindow;
[MBProgressHUD hideHUDForView:win animated:YES];
} +(void) showTextOnlyWithMBProgressHUDViewIn:(UIView*)view withText:(NSString*)text{
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
hud.mode = MBProgressHUDModeText;
hud.labelText = text;
hud.removeFromSuperViewOnHide = YES;
[hud hide:YES afterDelay:0.8f];
} +(void) showTextOnlyWithMBProgressHUDViewIn:(UIView*)view withText:(NSString*)text withTimeSeconds:(CGFloat)seconds {
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
hud.mode = MBProgressHUDModeText;
hud.labelText = text;
hud.removeFromSuperViewOnHide = YES;
[hud hide:YES afterDelay:seconds];
} +(void) showTextOnlyWithMBProgressHUDViewIn:(UIView*)view withDetailText:(NSString*)detailText withTimeSeconds:(CGFloat)seconds {
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
hud.mode = MBProgressHUDModeText;
hud.detailsLabelText = detailText;
hud.removeFromSuperViewOnHide = YES;
[hud hide:YES afterDelay:seconds];
} @end

可以下载通过github:https://github.com/cjt321/MyMBProgressUtil