iOS 验证码倒计时

来源:互联网 发布:增加usb电流软件 编辑:程序博客网 时间:2024/05/24 06:43

属性

@property (weak, nonatomic) IBOutlet UIButton *getCodeBtn;@property (nonatomic, assign) NSInteger secondsCountDown;@property (nonatomic, strong) NSTimer *countDownTimer;

方法

//倒计时- (void)timeOutAction{    _secondsCountDown = 60;    [_getCodeBtn setTitle:@"60 s" forState:(UIControlStateNormal)];    _getCodeBtn.backgroundColor = kSubTextColor;    _getCodeBtn.enabled = NO;    self.countDownTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeFireMethod) userInfo:nil repeats:YES];}-(void)timeFireMethod{    [_getCodeBtn setTitle:[NSString stringWithFormat:@"%ld s",(long)_secondsCountDown] forState:(UIControlStateNormal)];    _secondsCountDown--;    NSLog(@"%ld",_secondsCountDown);    if(_secondsCountDown == -1){        [_getCodeBtn setTitle:@"获取验证码" forState:(UIControlStateNormal)];        _getCodeBtn.backgroundColor = kBlueColor;        _getCodeBtn.enabled = YES;        [_countDownTimer invalidate];    }}
原创粉丝点击