分享

MBProgressHUD的基本使用

 昵称v8JFa 2015-11-04


  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];  

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多