MBProgressHUD elegantly prompts, mbprogresshud prompts

Source: Internet
Author: User

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];});

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.