MBProgressHUD的基本使用

来源:互联网 发布:新闻网站数据采集系统 编辑:程序博客网 时间:2024/04/28 06:21

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