发送验证码倒计时
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,要不然会闪烁
// 验证码 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,要不然会闪烁
相关文章推荐
- Uploadify上传文件中文文件名乱码 Java
- shiro框架---解决权限限制问题
- Activiti流程控制框架
- wemall5.0应用商店
- SpringMVC 4:文件上传和校验
- SharedPreferences使用详解
- 自定义样式
- Caused by: java.lang.NoSuchMethodException:
- viewgroup重写哦你measure方法
- JavaScript 解决浮点值运算Bug
- 工具类:时间的转换
- 工具类:递归遍历文件夹里所有文件
- 工具类:图片压缩处理
- 工具类:MD5加密
- BarTender10.1移动文本的幅度太大不要慌
- 栈的基本操作
- 例说javascript作用域
- PHP之Wamp修改项目目录
- PHP之Wamp修改端口
- GankApp 侧滑和title修改颜色的完整项目app