IOS 公共类-MyMBProgressUtil Progress显示

本文介绍了一个用于显示提示框的iOS公共类MyMBProgressUtil,该类对MBProgress进行了封装,提供了简洁的接口用于在视图或窗口上显示进度条并带文字提示。详细解释了类的接口用法,并提供了实现代码,便于开发者快速应用到项目中。

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 alun-chen 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/alunchen/p/5296422.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值