短信验证码 UI

来源:互联网 发布:个人域名 gmail 编辑:程序博客网 时间:2024/04/24 21:32
    //获取验证码    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);}