博客> iOS获取验证码倒计时操作
iOS获取验证码倒计时操作
2017-10-17 16:34 评论:0 阅读:78 CuiZhanQi
ios 获取验证码 倒计时

//获取验证码按钮被点击 -(void)doSomething{ / 一些操作 / self.timeDown = 120; self.timer = [NSTimer scheduledTimerWithTimeInterval:(1.0) target:self selector:@selector(handleTimer) userInfo:nil repeats:YES]; / 一些操作 / } // 倒计时 -(void)handleTimer { if(self.timeDown>=0) { [self.getBtn setUserInteractionEnabled:NO]; [self.getBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; int sec = ((self.timeDown%(24*3600))600); [self.getBtn setTitle:[NSString stringWithFormat:@"%d秒后重发",sec] forState:UIControlStateNormal]; }else{ [self.getBtn setUserInteractionEnabled:YES]; [self.getBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [self.getBtn setTitle:@"重发验证码" forState:UIControlStateNormal]; [self.timer invalidate]; } self.timeDown = self.timeDown - 1; }

收藏
0
sina weixin mail 回到顶部