A good IOS prompt box-mbprogresshud

Source: Internet
Author: User

Https://github.com/jdg/MBProgressHUD

Mbprogresshud works on any IOS version and is compatible with both arc and non-arc Projects


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.

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

If you need to configure the HUD You can do this by using the mbprogresshud reference that showhudaddedto: animated: returns.

MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];hud.mode = MBProgressHUDModeAnnularDeterminate;hud.labelText = @"Loading";[self doSomethingInBackgroundWithProgressCallback:^(float progress) {    hud.progress = progress;} completionCallback:^{    [hud hide:YES];}];

Ui updates shoshould always be done on the main thread. Some mbprogresshud setters are however considered "thread safe" and can be called from background threads. Those also includesetMode:,setCustomView:,setLabelText:,setLabelFont:,setDetailsLabelText:,setDetailsLabelFont:AndsetProgress:.

If you need to run your long-running task in the main thread, you shoshould perform it with a slight delay, so uikit will have enough time to update the UI (I. E ., draw the HUD) before you block the main thread with your task.

[MBProgressHUD showHUDAddedTo:self.view animated:YES];dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC);dispatch_after(popTime, dispatch_get_main_queue(), ^(void){    // Do something...    [MBProgressHUD hideHUDForView:self.view animated:YES];});

You shoshould be aware that any HUD updates issued inside the above block won't be displayed until the block completes.

For more examples, including how to use mbprogresshud with asynchronous operations such as nsurlconnection, take a look at the bundled Demo project. Extensive API documentation is provided in the header file (mbprogresshud. h ).

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.