MBProgressHUD 第三方详解学习

本文详细介绍了MBProgressHUD在iOS开发中的使用方法,包括初始化、设置样式、显示文本及进度条等多种模式,并展示了如何通过代理方法来实现HUD的隐藏。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  1. MBProgressHUD  

    //初始化                    

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

  2. HUD.delegate = self; 

  3. //常用的设置  

  4. //小矩形的背景色  

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

  6. //显示的文字  

  7. HUD.labelText = @"Test";  

  8. //细节文字  

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

  10. //是否有庶罩  

  11. HUD.dimBackground = YES;  

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

  13. //只显示文字  

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

  15. hud.mode = MBProgressHUDModeText;  

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

  17. hud.margin = 10.f;  

  18. hud.yOffset = 150.f;  

  19. hud.removeFromSuperViewOnHide = YES;  

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

  21. //方式2.initWithView  

  22. //use block  

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

  24. [self.view addSubview:HUD];  

  25. HUD.labelText = @"Test";  

  26. [HUD showAnimated:YES whileExecutingBlock:^{  

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

  28.     [self doTask];  

  29. } completionBlock:^{  

  30.     [HUD removeFromSuperview];  

  31.     [HUD release];          

  32. }];  

  33. //圆形进度条  

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

  35. [self.view addSubview:HUD];  

  36. HUD.mode = MBProgressHUDModeAnnularDeterminate;  

  37. HUD.delegate = self;  

  38. HUD.labelText = @"Loading";  

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

  40.  //自定义view  

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

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

  43. // Set custom view mode  

  44. HUD.mode = MBProgressHUDModeCustomView;  

  45. HUD.delegate = self;  

  46. HUD.labelText = @"Completed";  

  47. [HUD show:YES];  

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


  1. #pragma mark -  

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

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

  4. {  

  5.     [hud removeFromSuperview];  

  6.     hud = nil;  

  7. }  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值