短信验证码 UI

    //获取验证码
    UIButton* forgetCodeButton = [[UIButton alloc]init];
    [forgetCodeButton setTitle:@"获取验证码" forState:UIControlStateNormal];
    //右对齐
    [forgetCodeButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
    forgetCodeButton.titleLabel.font=[UIFont systemFontOfSize:12];
    [forgetCodeButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    forgetCodeButton.frame = CGRectMake(CGRectGetMaxX(_passwordTextField.frame), CGRectGetMinY(_passwordTextField.frame), 79, 29);
    forgetCodeButton.backgroundColor = NavThemeColor;
    forgetCodeButton.layer.cornerRadius = 5;
    forgetCodeButton.layer.masksToBounds = YES;
    [forgetCodeButton addTarget:self action:@selector(didClickForgetCodeButton) forControlEvents:UIControlEventTouchUpInside];
    [scrollView addSubview:forgetCodeButton];
    _forgetCodeBtn = forgetCodeButton;
    [self forgetCodeBtnNotClick];
    _forgetCodeBtnNum = 0;
    
//获取验证码点击
- (void)didClickForgetCodeButton{
    [self forgetCodeBtnNotClick];
    [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timeWithTimer:) userInfo:nil repeats:YES];
    _forgetCodeBtnNum = 59;
    [_forgetCodeBtn setTitle:[NSString stringWithFormat:@"60秒再次获取"] forState:UIControlStateNormal];
    [self callForgetCode];
}
- (void)timeWithTimer:(NSTimer *)timer
{
    if (_forgetCodeBtnNum>0) {
        [_forgetCodeBtn setTitle:[NSString stringWithFormat:@"%ld秒再次获取",(long)_forgetCodeBtnNum] forState:UIControlStateNormal];
    }else{
        [_forgetCodeBtn setTitle:[NSString stringWithFormat:@"获取验证码"] forState:UIControlStateNormal];
        [self forgetCodeBtnClickable];
        [timer invalidate];
    }
    _forgetCodeBtnNum--;
}
- (void)forgetCodeBtnClickable
{
    _forgetCodeBtn.userInteractionEnabled = YES;
    _forgetCodeBtn.backgroundColor = RGB_COLOR(80, 210, 194);
}
- (void)forgetCodeBtnNotClick
{
    _forgetCodeBtn.userInteractionEnabled = NO;
    _forgetCodeBtn.backgroundColor = RGB_COLOR(204, 211, 213);
}


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值