MBProgressHUD

  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. //再设置模式
  42. HUD.mode = MBProgressHUDModeAnnularDeterminate;  

    // 隐藏时候从父控件中移除

//    hud.removeFromSuperViewOnHide = YES;

    // 1秒之后再消失

//    [hud hide:YES afterDelay:0.7];

  1. HUD.delegate = self;  
  2. HUD.labelText = @"Loading";  
  3. [HUD showWhileExecuting:@selector(myProgressTask) onTarget:self withObject:nil animated:YES];  
  4.   
  5. //自定义view  
  6. HUD = [[MBProgressHUD alloc] initWithView:self.view];  
  7. HUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Checkmark.png"]] autorelease];  
  8. // Set custom view mode  
  9. HUD.mode = MBProgressHUDModeCustomView;  
  10. HUD.delegate = self;  
  11. HUD.labelText = @"Completed";  
  12. [HUD show:YES];  
  13. [HUD hide:YES afterDelay:3];  

代理方法:

[cpp]  view plain  copy
  1. #pragma mark -  
  2. #pragma mark HUD的代理方法,关闭HUD时执行  
  3. -(void)hudWasHidden:(MBProgressHUD *)hud  
  4. {  
  5.     [hud removeFromSuperview];  
  6.     [hud release];  
  7.     hud = nil;  
  8. }  

二个task

[cpp]  view plain  copy
  1.   -(void) doTask{  
  2.     //你要进行的一些逻辑操作  
  3.     sleep(2);  
  4.   }  
  5.   
  6.   -(void) myProgressTask{  
  7.        float progress = 0.0f;  
  8. while (progress < 1.0f) {  
  9.     progress += 0.01f;  
  10.     HUD.progress = progress;  
  11.     usleep(50000);  
  12. }  
  13.   
  14.   }  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值