首页 > 代码库 > ios 简单的倒计时验证码数秒过程实现
ios 简单的倒计时验证码数秒过程实现
- timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerFireMethod:) userInfo:nil repeats:YES];
- //倒计时方法验证码实现倒计时60秒,60秒后按钮变换开始的样子
- -(void)timerFireMethod:(NSTimer *)theTimer {
- if (seconds == 1) {
- [theTimer invalidate];
- seconds = 60;
- [validCodeBtn_ setTitle:@"获取验证码" forState: UIControlStateNormal];
- [validCodeBtn_ setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
- [validCodeBtn_ setEnabled:YES];
- }else{
- seconds--;
- NSString *title = [NSString stringWithFormat:MSG_DYNAMIC_CODE_WAIT,seconds];
- [validCodeBtn_ setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
- [validCodeBtn_ setEnabled:NO];
- [validCodeBtn_ setTitle:title forState:UIControlStateNormal];
- }
- }
- //如果登陆成功,停止验证码的倒数,
- - (void)releaseTImer {
- if (timer) {
- if ([timer respondsToSelector:@selector(isValid)]) {
- if ([timer isValid]) {
- [timer invalidate];
- seconds = 60;
- }
- }
- }
- }
ios 简单的倒计时验证码数秒过程实现
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。