美文网首页
NSTimer 验证码倒计时

NSTimer 验证码倒计时

作者: 走道牙的人 | 来源:发表于2016-08-18 15:53 被阅读73次

    参考http://blog.csdn.net/samuelltk/article/details/7484533

    参考http://www.cnblogs.com/pigpigDD/p/3975852.html

    参考http://blog.csdn.net/openglnewbee/article/details/51508301

    验证码倒计时示例代码

    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view from its nib.
        self.oldGetVerifyBtn.tag = 59;
    }
    
    /**
     *  获取原手机号验证码
     */
    - (IBAction)getOldVerify {
        
        [self getVerifyWithMobileNum:self.mobileNum];
    
        NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(refreshBtn1:) userInfo:nil repeats:YES];
        [timer fire];
    }
    
    - (void)refreshBtn1:(NSTimer *)timer
    {
        [self refreshBtnWithTimer:timer button:self.oldGetVerifyBtn];
    }
    
    - (void)refreshBtnWithTimer:(NSTimer *)timer button:(UIButton *)btn
    {
        NSInteger i = btn.tag;
        btn.enabled = NO;
        btn.backgroundColor = [UIColor lightGrayColor];
        [btn setTitle:[NSString stringWithFormat:@"剩余%zd秒", i] forState:UIControlStateDisabled];
        if (i == 0) {
            btn.enabled = YES;
            btn.backgroundColor = DBGold;
            [btn setTitle:@"获取验证码" forState:UIControlStateNormal];
            btn.tag = 59;
            [timer invalidate];
            return;
        }
        i--;
        btn.tag = i;
    }
    

    相关文章

      网友评论

          本文标题:NSTimer 验证码倒计时

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