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
- #import <UIKit/UIKit.h>
- #import "MBProgressHUD.h"
- @interface Viewcontroller:uiviewcontroller
- {
- //hud (head-up display, meaning the meaning of the heads up)
- 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):
[CPP]View Plaincopy
- -(Ibaction) Showtextdialog: (ID) Sender {
- //Initialize the progress box in the 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;
- //Set dialog box text
- Hud.labeltext = @"Please wait a moment";
- //Display dialog box
- [HUD Showanimated:yes whileexecutingblock:^{
- actions to be performed when the//dialog box is displayed
- Sleep (3);
- } completionblock:^{
- //Cancel the dialog after the operation has finished executing
- [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;
- 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;
- //Specify the offset of the x and Y axes from the center point, and display in the middle of the screen if not specified
- 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 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