您的位置:首页 > 其它

发送验证码倒计时

2015-10-26 00:00 288 查看
摘要: 倒计时

// 验证码 60秒倒计时
#define TIME_END_SECOND 60

定义全局变量:
NSInteger seconds;

-(void)setGetchecktitle
{
[self.getCodeBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerFireMethod:) userInfo:nil repeats:YES];
}

-(void)timerFireMethod:(NSTimer *)theTimer {
if (seconds == 0) {
[theTimer invalidate];
seconds = TIME_END_SECOND;
[getCodeBtn setTitle:@"获取验证码" forState: UIControlStateNormal];
[_getCodeBtn setEnabled:YES];

}else{
seconds--;
[theTimer timeInterval];

[self.getCodeBtn setEnabled:NO];
[self.getCodeBtn setTitle:timeStr forState:UIControlStateNormal];
NSString *timeStr = [NSString stringWithFormat:@"%d秒后重获取", seconds];
[self.getCodeBtn setTitle:timeStr forState:UIControlStateNormal];
}
}

//手机号码验证
-(BOOL)isValidatePhoneNumber:(NSString *)number
{
NSString *phoneRegex = @"^1[3|4|5|7|8][0-9]\\d{8}";
NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES%@",phoneRegex];
BOOL isyes = [phoneTest evaluateWithObject:number];

return isyes;
}

//设置button 上得文字右对齐

[checkBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];

提示:这里的button 设置为costom,要不然会闪烁
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: