Cue box third-party library Mbprogresshud IOS toast effect dynamic cue box effect

Source: Internet
Author: User

Cue box third-party library Mbprogresshud IOS toast effect dynamic cue box effect2014-08-11 17:39 11614 People read comments (0) favorite reports Classification:iOS-related (+)

Article from: http://blog.csdn.net/ryantang03/article/details/7877120

Mbprogresshud is an open source project that implements a number of Style prompt boxes that are simple, easy to use, and can be customized for the displayed content, are powerful, and are used in many projects. To GitHub can be downloaded to the project source code Https://github.com/jdg/MBProgressHUD, After downloading the MBProgressHUD.h and MBPROGRESSHUD.M directly into the project, do not forget to choose to copy to the project. You can start using the import header file where you need to use it. First look at the project:

Next is the entire demo of the full interface, here I only choose a few common dialog boxes, other styles in the source provided by the demo can be found, to use the direct reference can be.


Next directly on the code, the header file section:

[CPP]View Plaincopy
  1. #import <UIKit/UIKit.h>
  2. #import "MBProgressHUD.h"
  3. @interface Viewcontroller:uiviewcontroller
  4. {
  5. //hud (head-up display, meaning the meaning of the heads up)
  6. Mbprogresshud *hud;
  7. }
  8. -(Ibaction) Showtextdialog: (ID) sender;
  9. -(Ibaction) Showprogressdialog: (ID) sender;
  10. -(Ibaction) SHOWPROGRESSDIALOG2: (ID) sender;
  11. -(Ibaction) Showcustomdialog: (ID) sender;
  12. -(Ibaction) Showalltextdialog: (ID) sender;
  13. @end

Implementation file (Button implementation section):

[CPP]View Plaincopy
  1. -(Ibaction) Showtextdialog: (ID) Sender {
  2. //Initialize the progress box in the current view
  3. HUD = [[Mbprogresshud alloc] initWithView:self.view];
  4. [Self.view Addsubview:hud];
  5. //If this property is set, the current view is placed in the background
  6. Hud.dimbackground = YES;
  7. //Set dialog box text
  8. Hud.labeltext = @"Please wait a moment";
  9. //Display dialog box
  10. [HUD Showanimated:yes whileexecutingblock:^{
  11. actions to be performed when the//dialog box is displayed
  12. Sleep (3);
  13. } completionblock:^{
  14. //Cancel the dialog after the operation has finished executing
  15. [HUD Removefromsuperview];
  16. [HUD release];
  17. HUD = nil;
  18. }];
  19. }
  20. -(Ibaction) Showprogressdialog: (ID) Sender {
  21. HUD = [[Mbprogresshud alloc] initWithView:self.view];
  22. [Self.view Addsubview:hud];
  23. Hud.labeltext = @"Loading";
  24. //Setup mode is progress box-shaped
  25. Hud.mode = mbprogresshudmodedeterminate;
  26. [HUD Showanimated:yes whileexecutingblock:^{
  27. float progress = 0.0f;
  28. While (Progress < 1.0f) {
  29. Progress + = 0.01f;
  30. Hud.progress = progress;
  31. Usleep (50000);
  32. }
  33. } completionblock:^{
  34. [HUD Removefromsuperview];
  35. [HUD release];
  36. HUD = nil;
  37. }];
  38. }
  39. -(Ibaction) SHOWPROGRESSDIALOG2: (ID) Sender {
  40. HUD = [[Mbprogresshud alloc] initWithView:self.view];
  41. [Self.view Addsubview:hud];
  42. Hud.labeltext = @"Loading";
  43. Hud.mode = mbprogresshudmodeannulardeterminate;
  44. [HUD Showanimated:yes whileexecutingblock:^{
  45. float progress = 0.0f;
  46. While (Progress < 1.0f) {
  47. Progress + = 0.01f;
  48. Hud.progress = progress;
  49. Usleep (50000);
  50. }
  51. } completionblock:^{
  52. [HUD Removefromsuperview];
  53. [HUD release];
  54. HUD = nil;
  55. }];
  56. }
  57. -(Ibaction) Showcustomdialog: (ID) Sender {
  58. HUD = [[Mbprogresshud alloc] initWithView:self.view];
  59. [Self.view Addsubview:hud];
  60. Hud.labeltext = @"Operation succeeded";
  61. Hud.mode = Mbprogresshudmodecustomview;
  62. Hud.customview = [[[Uiimageview alloc] initwithimage:[uiimage imagenamed:@"Checkmark"]] autorelease];
  63. [HUD Showanimated:yes whileexecutingblock:^{
  64. Sleep (2);
  65. } completionblock:^{
  66. [HUD Removefromsuperview];
  67. [HUD release];
  68. HUD = nil;
  69. }];
  70. }
  71. -(Ibaction) Showalltextdialog: (ID) Sender {
  72. HUD = [[Mbprogresshud alloc] initWithView:self.view];
  73. [Self.view Addsubview:hud];
  74. Hud.labeltext = @"Operation succeeded";
  75. Hud.mode = Mbprogresshudmodetext;
  76. //Specify the offset of the x and Y axes from the center point, and display in the middle of the screen if not specified
  77. Hud.yoffset = 150.0f;
  78. Hud.xoffset = 100.0f;
  79. [HUD Showanimated:yes whileexecutingblock:^{
  80. Sleep (2);
  81. } completionblock:^{
  82. [HUD Removefromsuperview];
  83. [HUD release];
  84. HUD = nil;
  85. }];
  86. }

The following results are achieved in turn:

The following effect is similar to a toast in Android:

The above is a brief introduction of the use of Mbprogresshud, which are used in the form of block, so write code to more intuitive and more efficient

Cue box third-party library Mbprogresshud IOS toast effect dynamic cue box effect

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.