Basic use of Mbprogresshud

Source: Internet
Author: User

 Basic use of MbprogresshudCategory: IOS2012-10-30 11:19 12047 People read Comments (2) favorite reports

and GitHub on the demo in fact, is the small finishing, when the memo, want to do a complex effect can refer to Mbprogresshud on GitHub demo, writing is also very clear.

Download the MBProgressHUD.h and. m files first and drag them into the project. Address: Mbprogresshud

Here is the code: (Define Mbprogresshud *hud first in the. h file;)

[CPP]View Plaincopy
  1. Mode 1. Show directly on view
  2. HUD = [[Mbprogresshud ShowHUDAddedTo:self.view Animated:yes] retain];
  3. Hud.delegate = self;
  4. Common settings
  5. Background color of small rectangle
  6. Hud.color = [Uicolor Clearcolor]; //Here means no background
  7. Text to display
  8. Hud.labeltext = @"Test";
  9. Detail text
  10. Hud.detailslabeltext = @"Test detail";
  11. Is there a Shu hood?
  12. Hud.dimbackground = YES;
  13. [HUD Hide:yes Afterdelay:2];
  14. Show Text Only
  15. Mbprogresshud *hud = [Mbprogresshud showHUDAddedTo:self.view animated:yes];
  16. Hud.mode = Mbprogresshudmodetext;
  17. Hud.labeltext = @"Some message ...";
  18. Hud.margin = 10.F;
  19. Hud.yoffset = 150.F;
  20. Hud.removefromsuperviewonhide = YES;
  21. [HUD Hide:yes Afterdelay:3];
  22. Mode 2.initWithView
  23. Use block
  24. HUD = [[Mbprogresshud alloc] initWithView:self.view];
  25. [Self.view Addsubview:hud];
  26. Hud.labeltext = @"Test";
  27. [HUD Showanimated:yes whileexecutingblock:^{
  28. NSLog (@"%@", @"do somethings ...");
  29. [Self dotask];
  30. } completionblock:^{
  31. [HUD Removefromsuperview];
  32. [HUD release];
  33. }];
  34. Round progress bar
  35. HUD = [[Mbprogresshud alloc] initWithView:self.view];
  36. [Self.view Addsubview:hud];
  37. Hud.mode = mbprogresshudmodeannulardeterminate;
  38. Hud.delegate = self;
  39. Hud.labeltext = @"Loading";
  40. [HUD showwhileexecuting: @selector (myprogresstask) ontarget:self Withobject:nil Animated:yes];
  41. Custom View
  42. HUD = [[Mbprogresshud alloc] initWithView:self.view];
  43. Hud.customview = [[[Uiimageview alloc] initwithimage:[uiimage imagenamed:@"37x-checkmark.png"]] autorelease];
  44. Set Custom View mode
  45. Hud.mode = Mbprogresshudmodecustomview;
  46. Hud.delegate = self;
  47. Hud.labeltext = @"Completed";
  48. [HUD Show:yes];
  49. [HUD Hide:yes Afterdelay:3];

Proxy method:

[CPP]View Plaincopy < param name= "wmode" value= "Transparent" >
    1. #pragma mark-
    2. #pragma the agent method of the Mark HUD, which executes when the HUD is turned off
    3. -(void) Hudwashidden: (Mbprogresshud *) HUD
    4. {
    5. [HUD Removefromsuperview];
    6. [HUD release];
    7. HUD = nil;
    8. }

Two task

[CPP]View Plaincopy
  1. -(void) dotask{
  2. //Some logical operations you want to do
  3. Sleep (2);
  4. }
  5. -(void) myprogresstask{
  6. float progress = 0.0f;
  7. while (Progress < 1.0f) {
  8. Progress + = 0.01f;
  9. Hud.progress = progress;
  10. Usleep (50000);
  11. }
  12. }

Basic use of Mbprogresshud

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.