GitHub URL
Mbprogresshud is an open-source third-party class library that provides prompts in many styles, similar to activity indicator. It is easy to use and can customize the displayed content. It has powerful functions, it is used in many projects.
Mbprogresshud is an iOS drop-in class that displays a translucent HUD with an indicator and/or labels while
Work is being done in a background thread. The HUD is meant as a replacement for the unencrypted ented, private uikit uiprogresshud with some additional features.
Usage
The main guideline you need to follow when dealing with mbprogresshud while running long-running tasks is keeping the main thread work-free, so the UI can be updated promptly. the recommended way of using mbprogresshud is therefore to set it up on the main
Thread and then spinning the task, that you want to perform, off onto a new thread.
When a program executes a long task (such as a network request), you can use this class library to add a prompt box in the main window to display the progress or related prompts.
[MBProgressHUD showHUDAddedTo:self.view animated:YES];dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{ // Do something... dispatch_async(dispatch_get_main_queue(), ^{ [MBProgressHUD hideHUDForView:self.view animated:YES]; });});
This class library provides a variety of setting methods to build a satisfactory prompt box. Download this project on GitHub contains a demo that covers the basic setting methods.
Below is a simple record.
//Add a new HUD to the view
Mbprogresshud * HUD;
HUD = [[Mbprogresshud alloc] initwithview:Self. navigationcontroller. View];
[Self. navigationcontroller. ViewAddsubview:HUD];
// Regiser for HUD callbacks so we can remove it from the window at the right timeSet proxy
HUD. Delegate = SelF;
// Show the HUD while the provided method executes in a new thread
Show the HUD and execute other operations at the same time
[HUD showwhileexecuting: @ selector (mytask) ontarget: Self withobject: Nil animated: Yes];
// Set relevant text prompt information
HUD. Labeltext= @ "Loading ";
HUD. Detailslabeltext= @ "Updating
Data ";
// Set the HUD color to display with a color
HUD. Color= [Uicolor colorwithred: 0.23 Green: 0.50 Blue: 0.82 ALPHA: 0.90];
//Set determinate Mode
Hud. mode = mbprogresshudmodedeterminate;
// The HUD mode includes the following:
Typedef Enum {
/** Progress is shown using an uiactivityindicatorview. This is the default .*/(The default is uiactivityindicatorview)
Mbprogresshudmodeindeterminate,
/** Progress is shown using a round, pie-chart like, progress view .*/(Similar to a pie chart)
Mbprogresshudmodedeterminate,
/** Progress is shown using a ring-shaped progress view .*/(Like a ring)
Mbprogresshudmodeannulardeterminate,
/** Shows a custom view */(Custom)
Mbprogresshudmodecustomview,
/** Shows only labels */(Plain text)
Mbprogresshudmodetext
} Mbprogresshudmode;
When mode is set to custom, you need to set the custom View
Hud. customview = [[uiimageview alloc] initwithimage: [uiimage imagenamed: @ "37x-checkmark.png"];
Use Blocks
[HUD showanimated: Yes whileexecutingblock: ^ {
[Self mytask]; // other operations executed during the HUD display process
} Completionblock: ^ {
[HUD removefromsuperview];
}];
// Set the background of the view where the HUD is displayed to be dimmed.
Hud. dimbackground = yes;
// Set the progress of the HUD
Hud. Progress
// Others
-(Void) show :( bool) animated;
-(Void) Hide :( bool) animated;
-(Void) Hide :( bool) animated afterdelay :( nstimeinterval) delay;