验证码倒计时

作者: 雪精灵是我 | 来源:发表于2016-12-14 10:59 被阅读103次

    属性:

    UIButton *rightButton;//获取验证码

    NSTimer *_timer;

    NSInteger time;

    初始化时间 :time=60;

    功能:

    #pragma mark =======获取验证码

    - (void)codeClick:(UIButton *)button{

    [self.view endEditing:YES];

    BOOL isPhone = [Ht_control isMobileNumber:mobileTextField.text];

    if (!isPhone) {

    [Ht_control showMessage:@"请输入有效手机号"];

    return;

    }

    [self creatCodeData];

    }

    #pragma mark ====获取验证码

    - (void)creatCodeData{

    rightButton.enabled = NO;

    [rightButton setTitle:[NSString stringWithFormat:@"获取验证码(%zi)", time] forState:UIControlStateNormal];

    _timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeDown) userInfo:nil repeats:YES];

    //请求数据


    }

    - (void)timeDown

    {

    time --;

    if (time == 0) {

    [rightButton setTitle:@"重新获取" forState:UIControlStateNormal];

    rightButton.enabled = YES;

    [_timer invalidate];

    _timer = nil;

    time = 60;

    return;

    }

    [rightButton setTitle:[NSString stringWithFormat:@"获取验证码(%zi)", time] forState:UIControlStateNormal];

    }

    相关文章

      网友评论

      本文标题:验证码倒计时

      本文链接:https://www.haomeiwen.com/subject/uzpjpttx.html