MBProgressHUD的基本使用

MBProgressHUD的基本使用

原文:

http://my.oschina.net/jilin/blog/393005


  1. //方式1.直接在View上show  

  2. HUD = [[MBProgressHUD showHUDAddedTo:self.view animated:YES] retain];  

  3. HUD.delegate = self;  

  4.   

  5. //常用的设置  

  6. //小矩形的背景色  

  7. HUD.color = [UIColor clearColor];//这儿表示无背景  

  8. //显示的文字  

  9. HUD.labelText = @"Test";  

  10. //细节文字  

  11. HUD.detailsLabelText = @"Test detail";  

  12. //是否有庶罩  

  13. HUD.dimBackground = YES;  

  14. [HUD hide:YES afterDelay:2];  

  15.   

  16. //只显示文字  

  17. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];  

  18. hud.mode = MBProgressHUDModeText;  

  19. hud.labelText = @"Some message...";  

  20. hud.margin = 10.f;  

  21. hud.yOffset = 150.f;  

  22. hud.removeFromSuperViewOnHide = YES;  

  23. [hud hide:YES afterDelay:3];  

  24.   

  25. //方式2.initWithView  

  26. //use block  

  27. HUD = [[MBProgressHUD alloc] initWithView:self.view];  

  28. [self.view addSubview:HUD];  

  29. HUD.labelText = @"Test";  

  30. [HUD showAnimated:YES whileExecutingBlock:^{  

  31.     NSLog(@"%@",@"do somethings....");  

  32.     [self doTask];  

  33. } completionBlock:^{  

  34.     [HUD removeFromSuperview];  

  35.     [HUD release];          

  36. }];  

  37.   

  38. //圆形进度条  

  39. HUD = [[MBProgressHUD alloc] initWithView:self.view];  

  40. [self.view addSubview:HUD];  

  41. HUD.mode = MBProgressHUDModeAnnularDeterminate;  

  42. HUD.delegate = self;  

  43. HUD.labelText = @"Loading";  

  44. [HUD showWhileExecuting:@selector(myProgressTask) onTarget:self withObject:nil animated:YES];  

  45.   

  46. //自定义view  

  47. HUD = [[MBProgressHUD alloc] initWithView:self.view];  

  48. HUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Checkmark.png"]] autorelease];  

  49. // Set custom view mode  

  50. HUD.mode = MBProgressHUDModeCustomView;  

  51. HUD.delegate = self;  

  52. HUD.labelText = @"Completed";  

  53. [HUD show:YES];  

  54. [HUD hide:YES afterDelay:3];  

代理方法:

[cpp] view plaincopy

  1. #pragma mark -  

  2. #pragma mark HUD的代理方法,关闭HUD时执行  

  3. -(void)hudWasHidden:(MBProgressHUD *)hud  

  4. {  

  5.     [hud removeFromSuperview];  

  6.     [hud release];  

  7.     hud = nil;  

  8. }  



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值