iOS Learning note 29-Mbprogresshud The third-party library of the Cue box

Source: Internet
Author: User
Tags usleep uikit

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:

#import <UIKit/UIKit.h> #import "MBProgressHUD.h" @interface viewcontroller:uiviewcontroller{//hud (head-up Display, meaning the meaning of the Mbprogresshud *hud;} -(Ibaction) Showtextdialog: (ID) sender;-(ibaction) Showprogressdialog: (ID) sender;-(ibaction) ShowProgressDialog2: ( ID) sender;-(ibaction) Showcustomdialog: (ID) sender;-(ibaction) Showalltextdialog: (ID) sender; @end


Implementation file (Button implementation section):

-  (ibaction) Showtextdialog: (ID) sender {    //Initialization Progress box, placed in Current view      hud = [[mbprogresshud alloc] initwithview:self.view];    [ self.view addsubview:hud];        //If this property is set, the current view is placed in the background      hud.dimbackground = yes;        //Setting dialog box text     hud.labeltext = @ "Please wait a moment";         // Show dialog Box     [HUD showAnimated:YES whileExecutingBlock:^{         //What you need to do when the dialog box is displayed         sleep (3);   Cancel dialog box after   } completionblock:^{        //operation finishes          [HUD removeFromSuperview];         [hud release];        hud = nil;    }];} -  (ibaction) Showprogressdialog: (ID) Sender {    hud = [[mbprogresshud  alloc] initWithView:self.view];    [self.view addSubview:HUD];     hud.labeltext = @ "Loading";         //Setup mode is progress box-shaped     HUD.mode = MBProgressHUDModeDeterminate;    [HUD  showanimated:yes whileexecutingblock:^{        float  progress = 0.0f;        while  (progress <  1.0f)  {            progress +=  0.01f;            hud.progress =  Progress;       &nbSp;    usleep (50000);        }     } completionBlock:^{        [HUD removeFromSuperview];         [HUD release];         hud = nil;    }];} -  (ibaction) SHOWPROGRESSDIALOG2: (ID) Sender {    hud = [[mbprogresshud  alloc] initWithView:self.view];    [self.view addSubview:HUD];     hud.labeltext = @ "Loading";    hud.mode =  Mbprogresshudmodeannulardeterminate;        [hud showanimated:yes  whileExecutingBlock:^{        float progress =  0.0f;        while  (progress < 1.0f)  {            progress += 0.01f;             HUD.progress = progress;             usleep (50000);         }    } completionBlock:^{         [HUD removeFromSuperview];        [HUD release];         hud = nil;    }];} -  (ibaction) Showcustomdialog: (ID) Sender {    hud = [[mbprogresshud  alloc] initWithView:self.view];    [self.view addSubview:HUD];     hud.labeltext = @ "Operation succeeded";    hud.mode =  mbprogresshudmodecustomview;     hud.customview = [[[uiimageview alloc] initwithimage:[uiimage imagenamed:@ "Checkmark" ]] autorelease];    [hud showanimated:yes whileexecutingblock:^{         sleep (2);    } completionblock:^{         [HUD removeFromSuperview];         [HUD release];        HUD = nil;     }];    }-  (ibaction) Showalltextdialog: (ID) sender {     hud = [[mbprogresshud alloc] initwithview:self.view];    [ self.view addsubview:hud];    hud.labeltext = @ "Operation succeeded";     hud.mode = mbprogresshudmodetext;        // Specifies the offset from the X and Y axes of the center point, and if not specified, displays the//&nbsp in the middle of the screen;   hud.yoffset = 150.0f;//    hud.xoffset = 100.0f;         [HUD showAnimated:YES whileExecutingBlock:^{         sleep (2);    } completionblock:^{         [HUD removeFromSuperview];         [HUD release];        HUD = nil;     }];}


The following results are achieved in turn:




The following effect is similar to a toast in Android:


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

to join our QQ group or public account please check: Ryan ' s zone public account and QQ Group


Welcome to follow my Sina Weibo and I exchange: @ Tang Yu _ryan


iOS Learning note 29-Mbprogresshud The third-party library of the Cue box

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.