发送短信验证码按钮 定时器
Posted 宁静暖风
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了发送短信验证码按钮 定时器相关的知识,希望对你有一定的参考价值。
static int i = 29; @property(nonatomic,strong) NSTimer *timmer;//定时器 - (void)sendNumber{ NSLog(@"发送验证码"); self.getTelephoneCodeBtn.enabled = NO; [self.getTelephoneCodeBtn setTitle:@"已发送" forState:UIControlStateDisabled]; [self.getTelephoneCodeBtn setBackgroundColor:[UIColor grayColor]]; //初始化定时器 _timmer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(test:) userInfo:nil repeats:YES]; } - (void)test:(NSTimer *)timmer{ NSString *str = [NSString stringWithFormat:@"%d后重试",i]; [self.getTelephoneCodeBtn setTitle:str forState:UIControlStateDisabled]; i--; if (i == -1) { [timmer invalidate]; self.getTelephoneCodeBtn.enabled = YES; [self.getTelephoneCodeBtn setTitle:@"发送验证码" forState:UIControlStateNormal]; [self.getTelephoneCodeBtn setBackgroundColor:getColor(@"fa2671")]; i = 29; } }
以上是关于发送短信验证码按钮 定时器的主要内容,如果未能解决你的问题,请参考以下文章