美文网首页
倒计时代码

倒计时代码

作者: ljzza | 来源:发表于2018-03-28 13:48 被阅读0次
    -(void)getCodeSuccess
    {
        self.codeButton.enabled = NO;
        self.number = 59;
        self.timmer = [NSTimer timerWithTimeInterval:1.0f target:self selector:@selector(changeGetCodeButtonTitle) userInfo:nil repeats:YES];
        [[NSRunLoop currentRunLoop] addTimer:self.timmer forMode:NSRunLoopCommonModes];
        [self.timmer fire];
        self.touched = NO;
    }
    
    //更换,获取验证码按钮标题
    - (void)changeGetCodeButtonTitle
    {
        self.codeButton.titleLabel.text = [NSString stringWithFormat:@"%d秒后重试",(self.number)];
        [self.codeButton setTitle:[NSString stringWithFormat:@"%d秒后重试",(self.number)] forState:UIControlStateDisabled];
        self.number--;
        if (self.number == 0) {
            [self.timmer invalidate];
            self.timmer = nil;
            [self.codeButton setTitle:@"重新获取" forState:UIControlStateNormal];
            self.codeButton.enabled = YES;
        }
    }
    

    相关文章

      网友评论

          本文标题:倒计时代码

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