美文网首页
60s倒计时

60s倒计时

作者: onlyyourself | 来源:发表于2017-02-22 16:21 被阅读10次

    @property (nonatomic ,assign)NSInteger secondsCountDown;//倒计时的总时间
    @property (nonatomic ,strong)NSTimer *countDownTimer;//定时器

    //写入BUT点击事件
    -(void)buttonDidClock{
    //设置倒计时总时长
    self.secondsCountDown = 60;
    self.countDownTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(startTimeNSTimer) userInfo:nil repeats:YES];
    [self.capthaButton setTitle:[NSString stringWithFormat:@"%ld秒后重新发送",(long)self.secondsCountDown] forState:UIControlStateNormal];
    }

    //使用NSTimer实现倒计时

    • (void)startTimeNSTimer

    {
    self.secondsCountDown -- ;
    self.capthaButton.userInteractionEnabled = NO;
    [self.capthaButton setTitle:[NSString stringWithFormat:@"%ld秒后重新发送",(long)self.secondsCountDown] forState:UIControlStateNormal];
    if (self.secondsCountDown == 0) {
    [self.countDownTimer invalidate];
    self.capthaButton.userInteractionEnabled = YES;
    [self.capthaButton setTitle:@"重新发送验证码" forState:UIControlStateNormal];
    }

    }

    相关文章

      网友评论

          本文标题:60s倒计时

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