IOS study notes 29-Prompt box mbprogresshud of a third-party library

Source: Internet
Author: User
Tags usleep

Mbprogresshud is an open-source project that provides prompt boxes of many styles. It is easy to use and convenient to customize the displayed content. It has powerful functions, it is used in many projects. You can download the project source code repository to GitHub. After importing the header file, you can start using it. First, take a look at the project:


Next is the complete interface of the entire demo. Here I only select a few commonly used dialogs. other styles can be found in the demo provided by the source code. If you want to use them, you can directly refer to them.


Next we will directly go to the Code, header file:

# Import <uikit/uikit. h> # import "mbprogresshud. H "@ interface viewcontroller: uiviewcontroller {// HUD (head-up display) 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 Part ):

-(Ibaction) showtextdialog :( ID) sender {// initialization progress box, placed in the current view HUD = [[mbprogresshud alloc] initwithview: Self. view]; [self. view addsubview: HUD]; // if this attribute is set, the current view is placed in the background Hud. dimbackground = yes; // set the dialog box text Hud. labeltext = @ "Please wait"; // displayed dialog box [HUD showanimated: Yes whileexecutingblock: ^ {// the operation to be executed when the dialog box is displayed sleep (3);} completionblock: ^ {// cancel the dialog box [HUD removefromsuperview]; [HUD release]; HUD = nil ;}] ;}- (ibaction) showprogressdialog :( ID) after the operation is completed) sender {HUD = [[mbprogresshud alloc] initwithview: Self. view]; [self. view addsubview: HUD]; HUD. labeltext = @ "loading"; // set the mode to progress-framed Hud. mode = mbprogresshudmodedeterminate; [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) 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 successful"; 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 successful"; HUD. mode = mbprogresshudmodetext; // specify the offset between the X axis and the Y axis of the distance from the central point. If this parameter is not specified, the image is displayed in the middle of the screen. // Hud. yoffset = 150366f; // Hud. xoffset = 100366f; [HUD showanimated: Yes whileexecutingblock: ^ {sleep (2);} completionblock: ^ {[HUD removefromsuperview]; [HUD release]; HUD = nil;}];}

The results are as follows:




The following figure shows the effect of toast in Android:


The above briefly introduces the use of mbprogresshud. Here we use block to operate it, so that the code is more intuitive and efficient.

To join our QQ group or public account, see: Ryan's
Zone public account and QQ Group

Welcome to my Sina Weibo chat: @ Tang Ren _ Ryan

Related Article

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.