定时、延时执行

2019-07-30  本文已影响0人  Cy_Star
[NSThread sleepForTimeInterval:1];  //延时1秒

/

count = 30;
// userInfo:可以传需要做出变化的对象
NSTimer *  _timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(countdown:) userInfo: lable repeats:YES];
       

-(void)countdown:(NSTimer *)timer
{
    UILable * lable = [timer userInfo];
    NSString * str = [NSString stringWithFormat:@"重新发送(%d)",count];
    lable.text = str;
    lable.backgroundColor = [UIColor colorWithRed:220/255.0 green:220/255.0  blue:220/255.0  alpha:1];
    count--;
    if (count < 0)
    {
        lable.text = @"发送验证码";
        lable.backgroundColor = butColor;
        count = 30;
        [_timer invalidate];
        _timer = nil;
    }
}
上一篇 下一篇

猜你喜欢

热点阅读