All
I am trying to run UIActivityIndicator
for a 5 seconds on viewdidappear
method .But how do i give a time limit for activity indicator(5 seconds) ?
This is the code for UIActivityIndicator
UIActivityIndicatorView *activityView=[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
activityView.center=self.view.center;
[activityView startAnimating];
[self.view addSubview:activityView];
With one line and no additional dependencies & conditions:
[activityView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:5.0];
Set activity view to hide automatically when stopped
activityView.hidesWhenStopped = YES;
And hide it after 5s like this:
[activityView performSelector:@selector(stopAnimating) withObject:nil afterDelay:5.0];
This will allow you to start animation again by just calling startAnimating
if you need so in the future and keep pointer to the UIActivityIndicatorView
If you just need to show activity indicator once and will not use it anymore, Alexanders answer will suit best to your needs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With