开发者

NSTimer With ActivityIndicator

开发者 https://www.devze.com 2023-02-17 15:45 出处:网络
I want to stop开发者_开发百科 ActivityIndicator after some time. I guess this can be achieved if I call a method after some time which stops activity indicator.

I want to stop开发者_开发百科 ActivityIndicator after some time. I guess this can be achieved if I call a method after some time which stops activity indicator.

It can be achieved using NSTimer, but I don't know how. An example with code snippet will be great.


In .h class,

UIActivityIndicatorView *activity;

And used this code to your implementation class,

- (void)viewDidLoad {
    [super viewDidLoad];

    //initialise activityIndicator and add it to view
    activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    activity.frame = CGRectMake(150,200, 20, 20);
    [self.view addSubview:activity];
    [activity startAnimating];

    //call timer to fire after your required time
    [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(timerMethod:) userInfo:nil repeats:NO];
}

Timer Action,

-(void) timerMethod : (NSTimer *) theTimer {
    // after 1.5 seconds, the activity indicator will be hidden.
      [activity stopAnimating];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消