MBProgressHUD elegantly prompts, mbprogresshud prompts
Project homepage: MBProgressHUD
Download instance: Click to download
Quick Start:
When executing a task that requires a long time, the most important thing to use MBProgressHUD is to ensure that the main thread is idle, so that the UI can be updated in real time. therefore, we recommend that you use MBProgressHUD in the main thread to put other tasks you want to execute in other threads:
[MBProgressHUD showHUDAddedTo: self. view animated: YES]; dispatch_async (dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_LOW, 0), ^ {// execute some tasks... dispatch_async (dispatch_get_main_queue (), ^ {[MBProgressHUD hideHUDForView: self. view animated: YES] ;});
If you want to configure the HUD, you can use the MBProgressHUD instance returned by showHUDAddedTo: animated: method.
MBProgressHUD * hud = [MBProgressHUD showHUDAddedTo: self. view animated: YES]; hud. mode = MBProgressHUDModeAnnularDeterminate; hud. labelText = @ "Loading"; // doSomethngInBackgroudWithProgressCallback: Specifies a progress-related custom method. [self doSomethingInBackgroundWithProgressCallback: ^ (float progress) {hud. progress = progress;} completionCallback: ^ {[hud hide: YES];}];
UI updates should always be completed in the main thread. however, some MBProgressHUD configurators take "thread security" into account and can be called in the background thread. the seters specifically refer:setMode:
,setCustomView:
,setLabelText:
,setLabelFont:
,setDetailsLabelText:
,setDetailsLabelFont:
AndsetProgress:
.
If you need to execute a task that requires a long time to run in the main thread, you should execute the task after a short delay, so that before your task blocks the main thread, UIKit has enough time to update the UI (for example, drawing a HUD ).
[MBProgressHUD showHUDAddedTo: self. view animated: YES]; dispatch_time_t popTime = dispatch_time (DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC); dispatch_after (popTime, interval (), ^ (void) {// execute a time-consuming operation. [MBProgressHUD hideHUDForView: self. view animated: YES];});