1

Hi i am beginner in objective C. I have an ActivityIndicator in my project.

UIActivityIndicatorView *loading = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[loading setCenter:CGPointMake(450,400)];
[loading setColor:[UIColor blackColor]];
[self.view addSubview:loading];

Is it possible to stopAnimating this activity indicator after some specific time using Thread?

5
  • Do you mean stopping UIActivityIndicatorView animating from another thread? Commented Jul 10, 2018 at 9:00
  • Yes....I need to set up a thread that automatically stopAnimating my activity indicator after a specific time period. Commented Jul 10, 2018 at 9:03
  • I think you can use loading performSelector:@selector(stopAnimating) withObject:nil afterDelay:1];. Commented Jul 10, 2018 at 9:08
  • could you please explain this code? What is the purpose of afterDelay:1 Commented Jul 10, 2018 at 9:10
  • It makes loading call method stopAnimating after 1 second. You can change 1 to another number for different delay. For more information, you can take a look at this developer.apple.com/documentation/objectivec/nsobject/… Commented Jul 10, 2018 at 9:14

1 Answer 1

1

You can do it like

UIActivityIndicatorView *loading = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[loading setCenter:CGPointMake(450,400)];
[loading setColor:[UIColor blackColor]];
[self.view addSubview:loading];
// To stop after delay of 3 
[self performSelector:@selector(StopIndicator) withObject:nil afterDelay:3];

    -(void)StopIndicator
    {
    [loading stop];
    //[loading removeFromSuperview]; //uncomment if you want to remove it as well 

    }
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.