首页 > 其他 > 详细

发送验证码倒计时

时间:2015-10-26 17:05:52      阅读:259      评论:0      收藏:0      [点我收藏+]

// 验证码 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 设置为costom,要不然会闪烁

发送验证码倒计时

原文:http://my.oschina.net/sccx/blog/522183

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!