美文网首页
iOS获取倒计时按钮

iOS获取倒计时按钮

作者: Satanshun | 来源:发表于2016-10-18 09:47 被阅读0次

    //验证码时间

    @property (nonatomic,strong)NSTimer  *timer;

    //开始计时

    _timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(Countdown) userInfo:nil repeats:YES];

    //倒计时

    - (void)Countdown

    {

    static NSInteger time = 59;

    self.captchaButton.userInteractionEnabled = NO;

    self.captchaButton.alpha = 0.6;

    if (time > -1) {

    NSString *number = [NSString stringWithFormat:@"%ld",(long)time];

    [_captchaButton setTitle:number forState:UIControlStateNormal];

    } else {

    [_captchaButton setTitle:@"获取" forState:UIControlStateNormal];

    self.captchaButton.userInteractionEnabled = YES;

    self.captchaButton.alpha = 1;

    [_timer invalidate];//停止计时器

    _timer = nil;//重置计时器

    time = 60;

    }

    time --;

    }

    [timer setFireDate:[NSDate date]]; //继续。

    [timer setFireDate:[NSDate distantPast]];//开启

    [timer setFireDate:[NSDate distantFuture]];//暂停

    相关文章

      网友评论

          本文标题:iOS获取倒计时按钮

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