IOS progress bar implementation

Source: Internet
Author: User

During iOS development, users often encounter similar situations such as reading system resources. If the network is relatively slow, users may think that the app has crashed and the user experience is poor, foreigners are still very good at providing open source sources and learning from each other.

The progress bar of iOS can be divided into several categories. There are common ones, such as a circle, text under a circle, and text directly ..

Add the following two files to your project: MBProgressHUD. h and MBProgressHUD. m. Next we only need to reference the header file of progress in our. m file.

For common progress bars, the Code is as follows:


[Plain]
-(IBAction) showSimple :( id) sender {
// The hud will dispable all input on the view (use the higest view possible in the view hierarchy)
HUD = [[MBProgressHUD alloc] initWithView: self. navigationController. view];
[Self. navigationController. view addSubview: HUD];

// Regiser for HUD callbacks so we can remove it from the window at the right time
HUD. delegate = self;

// Show the HUD while the provided method executes in a new thread
[HUD showWhileExecuting: @ selector (myTask) onTarget: self withObject: nil animated: YES];
}
The selector function myTask can do what we want to do:
[Plain]
-(Void) myTask {
// Do something usefull in here instead of sleeping...
Sleep (3 );
}

Effect

Progress bar with text:

[Plain]
-(IBAction) showWithLabel :( id) sender {

HUD = [[MBProgressHUD alloc] initWithView: self. navigationController. view];
[Self. navigationController. view addSubview: HUD];

HUD. delegate = self;
HUD. labelText = @ "Loading ";

[HUD showWhileExecuting: @ selector (myTask) onTarget: self withObject: nil animated: YES];
}
As follows:


Plain text code:

[Plain]
-(IBAction) showTextOnly :( id) sender {

MBProgressHUD * hud = [MBProgressHUD showHUDAddedTo: self. navigationController. view animated: YES];

// Configure for text only and offset down
Hud. mode = MBProgressHUDModeText;
Hud. labelText = @ "Some message ...";
Hud. margin = 10.f;
Hud. yOffset = 150.f;
Hud. removeFromSuperViewOnHide = YES;

[Hud hide: YES afterDelay: 3];
}

As follows:
 

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.