The program runs as shown below:
Click the button to implement the corresponding prompt box:
Here only one of the pictures, interested can run the program yourself, see a few other tips box yo!!!
third-party framework Mbprogresshud:Https://github.com/jdg/MBProgressHUD
The program code is as follows:
//
Viewcontroller.m
Third-party framework--hint box
//
Created by Mac1 on 15/10/5.
Copyright (c) 2015 www.iphonetrain.com. All rights reserved.
//
#import "ViewController.h"
#import "MBProgressHUD.h"
@interface Viewcontroller ()
-(Ibaction) Textdialog: (ID) sender;
-(Ibaction) PROGRESSDIALOG1: (ID) sender;
-(Ibaction) PROGRESSDIALOG2: (ID) sender;
-(Ibaction) Customdialog: (ID) sender;
-(Ibaction) Alltextdialog: (ID) sender;
@end
@implementation Viewcontroller
-(void) Viewdidload {
[Super Viewdidload];
}
Text Prompt box
-(Ibaction) Textdialog: (ID) Sender {
Create a Progress box
__block Mbprogresshud *hud = [[Mbprogresshud Alloc]initwithview:self.view];
[Self.view Addsubview:hud];
Put the current view in the background
Hud.dimbackground = YES;
Set the text of the dialog box
Hud.labeltext = @ "Please wait a moment";
Show dialog box
[HUD Showanimated:yes whileexecutingblock:^{
What to do when the dialog box is displayed
Sleep (3);
} completionblock:^{
Actions that are performed after the operation is complete, suppress the dialog box
[HUD Removefromsuperview];
HUD = nil; Change object values in block, __block
}];
}
Progress Tip Box One
-(Ibaction) PROGRESSDIALOG1: (ID) Sender {
Create a Progress box
__block Mbprogresshud *hud = [[Mbprogresshud Alloc]initwithview:self.view];
[Self.view Addsubview:hud];
Hud.labeltext = @ "Loading";
Set Mode to Progress box
Hud.mode = mbprogresshudmodedeterminate;
Show Progress Box
[HUD Showanimated:yes whileexecutingblock:^{
Actions to perform when displayed
float progress = 0.0f;
while (Progress < 1.0f) {
Progress + = 0.01;
Hud.progress = progress;
Usleep (50000);
}
} completionblock:^{
Actions performed after completion
[HUD Removefromsuperview];
HUD = nil;
}];
}
Progress Prompt Box Two
-(Ibaction) PROGRESSDIALOG2: (ID) Sender {
Create a Progress box
__block Mbprogresshud *hud = [[Mbprogresshud Alloc]initwithview:self.view];
[Self.view Addsubview:hud];
Hud.labeltext = @ "Loading";
Set Mode to Progress box
Hud.mode = mbprogresshudmodeannulardeterminate;
Show Progress Box
[HUD Showanimated:yes whileexecutingblock:^{
Actions to perform when displayed
float progress = 0.0f;
while (Progress < 1.0f) {
Progress + = 0.01;
Hud.progress = progress;
Usleep (50000);
}
} completionblock:^{
Actions performed after completion
[HUD Removefromsuperview];
HUD = nil;
}];
}
Customizing the Progress Box
-(Ibaction) Customdialog: (ID) Sender {
Create a Progress box
__block Mbprogresshud *hud = [[Mbprogresshud Alloc]initwithview:self.view];
[Self.view Addsubview:hud];
Hud.labeltext = @ "Operation succeeded";
Hud.customview = [[Uiimageview alloc]initwithimage:[uiimage imagenamed:@ "Checkmark.png"]];
[HUD Showanimated:yes whileexecutingblock:^{
Sleep 2 seconds
Sleep (2);
} completionblock:^{
[HUD Removefromsuperview];
HUD = nil;
}];
}
Plain Text Prompt box
-(Ibaction) Alltextdialog: (ID) Sender {
Create a Progress box
__block Mbprogresshud *hud = [[Mbprogresshud Alloc]initwithview:self.view];
[Self.view Addsubview:hud];
Hud.labeltext = @ "You have operated on YO!!!";
Hud.mode = Mbprogresshudmodetext;
Specifies the offset of the displayed text, not specifying the default display in the middle of the screen
/*
Hud.xoffset = 150;
Hud.yoffset = 200;
*/
[HUD Showanimated:yes whileexecutingblock:^{
Sleep (3);
} completionblock:^{
[HUD Removefromsuperview];
HUD = nil;
}];
}
@end
Third-party framework Mbprogresshud-----implement various prompt boxes