- 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;
- }
- }
- }
- }
时间: 2024-12-13 23:45:48