/ Published in: Objective C
When performing tasks that may take some time, you often need to provide some kind of visual feedback to your users. If you know how long the task will take to complete, you can use a progress indicator to show the user how much of the task has been performed and how much still has to run. If you are unable to determine the duration of the task, use a “busy†indicator (such as the beach ball or hourglass on OS X).
iOS provides classes for showing both progress and activity.
iOS provides classes for showing both progress and activity.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// Showing progress NSTimer *timer; { UIProgressView *progress = [sender userInfo]; //have we completed? if (progress.progress == 1.0) [timer invalidate]; else progress.progress += 0.05; } - (void)viewDidLoad { [super viewDidLoad]; UIProgressView *myProgressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault]; CGRect progressFrame = CGRectMake(10,100,300,25); [myProgressView setFrame:progressFrame]; [myProgressView setProgress:0.0]; [self.view addSubview:myProgressView]; //create timer target:self selector:@selector(updateProgress:) userInfo:myProgressView repeats:YES] retain]; } // Showing Activity - (void)viewDidLoad { [super viewDidLoad]; [self.view setBackgroundColor:[UIColor blackColor]]; UIActivityIndicatorView *myActivityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; CGRect activityFrame = CGRectMake(130,100,50,50); [myActivityView setFrame:activityFrame]; myActivityView.hidesWhenStopped = YES; [myActivityView startAnimating]; [self.view addSubview:myActivityView]; }