IOS 公共类-MyMBProgressUtil Progress显示
此公共类用于显示提示框,对MBProgress的进一步封装。可以看下面的代码
接口:
1 @interface MyMBProgressUtil 2 3 //显示Progress在view上 4 +(void) showMBProgressHUDViewInView:(UIView*)view andText:(NSString*)text; 5 //隐藏Progress在view上 6 +(void) hiddenMBProgressHUDViewInView:(UIView *)view; 7 8 //显示Progress在window上 9 +(void) showMBProgressHUDViewInWindow;10 //隐藏Progress在window上11 +(void) hiddenMBProgressHUDViewInWindow;12 13 //显示文字在view上,默认0.8秒后隐藏14 +(void) showTextOnlyWithMBProgressHUDViewIn:(UIView*)view withText:(NSString*)text;15 //显示文字在view上,自己设定多少秒后隐藏16 +(void) showTextOnlyWithMBProgressHUDViewIn:(UIView*)view withText:(NSString*)text withTimeSeconds:(CGFloat)seconds;17 //显示详细文字在view上,自己设定多少秒后隐藏18 +(void) showTextOnlyWithMBProgressHUDViewIn:(UIView*)view withDetailText:(NSString*)detailText withTimeSeconds:(CGFloat)seconds;19 20 @end
实现类:
1 @implementation MyMBProgressUtil: NSObject 2 3 +(void) showMBProgressHUDViewInView:(UIView*)view andText:(NSString*)text { 4 MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES]; 5 hud.clipsToBounds = NO; 6 [hud setLabelText:text]; 7 hud.removeFromSuperViewOnHide = YES; 8 hud.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:0.3f]; 9 CGRect frame = CGRectMake(hud.frame.origin.x, hud.frame.origin.y, hud.frame.size.width-20, hud.frame.size.height-20);10 hud.frame = frame;11 }12 13 +(void)hiddenMBProgressHUDViewInView:(UIView *)view {14 [MBProgressHUD hideHUDForView:view animated:YES];15 }16 17 +(void) showMBProgressHUDViewInWindow {18 UIWindow *win = [UIApplication sharedApplication].keyWindow;19 MBProgressHUD *hud = [[MBProgressHUD alloc] initWithWindow:win];20 hud.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:0.3f];21 hud.mode = MBProgressHUDModeIndeterminate;22 hud.removeFromSuperViewOnHide = YES;23 [win addSubview:hud];24 [hud show:YES];25 }26 27 28 +(void) hiddenMBProgressHUDViewInWindow {29 UIWindow *win = [UIApplication sharedApplication].keyWindow;30 [MBProgressHUD hideHUDForView:win animated:YES];31 }32 33 +(void) showTextOnlyWithMBProgressHUDViewIn:(UIView*)view withText:(NSString*)text{34 MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];35 hud.mode = MBProgressHUDModeText;36 hud.labelText = text;37 hud.removeFromSuperViewOnHide = YES;38 [hud hide:YES afterDelay:0.8f];39 }40 41 +(void) showTextOnlyWithMBProgressHUDViewIn:(UIView*)view withText:(NSString*)text withTimeSeconds:(CGFloat)seconds {42 MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];43 hud.mode = MBProgressHUDModeText;44 hud.labelText = text;45 hud.removeFromSuperViewOnHide = YES;46 [hud hide:YES afterDelay:seconds];47 }48 49 +(void) showTextOnlyWithMBProgressHUDViewIn:(UIView*)view withDetailText:(NSString*)detailText withTimeSeconds:(CGFloat)seconds {50 MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];51 hud.mode = MBProgressHUDModeText;52 hud.detailsLabelText = detailText;53 hud.removeFromSuperViewOnHide = YES;54 [hud hide:YES afterDelay:seconds];55 }56 57 @end
可以下载通过github:https://github.com/cjt321/MyMBProgressUtil
posted on 2016-03-19 21:40 阅读( ...) 评论( ...)