美文网首页
定时、延时执行

定时、延时执行

作者: Cy_Star | 来源:发表于2019-07-30 16:36 被阅读0次
[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;
    }
}

相关文章

网友评论

      本文标题:定时、延时执行

      本文链接:https://www.haomeiwen.com/subject/xjpwnxtx.html