码迷,mamicode.com
首页 > 其他好文 > 详细

发送短信验证码按钮 定时器

时间:2017-08-21 23:03:18      阅读:421      评论:0      收藏:0      [点我收藏+]

标签:短信验证码   nat   发送   scheduled   nslog   target   hone   bsp   timer   

static int i = 29;
@property(nonatomic,strong) NSTimer *timmer;//定时器
- (void)sendNumber{
    NSLog(@"发送验证码");
    self.getTelephoneCodeBtn.enabled = NO;
    [self.getTelephoneCodeBtn setTitle:@"已发送" forState:UIControlStateDisabled];
    [self.getTelephoneCodeBtn setBackgroundColor:[UIColor grayColor]];
    //初始化定时器
    _timmer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(test:) userInfo:nil repeats:YES];
}

- (void)test:(NSTimer *)timmer{
    NSString *str = [NSString stringWithFormat:@"%d后重试",i];
    [self.getTelephoneCodeBtn setTitle:str forState:UIControlStateDisabled];
    i--;
    if (i == -1) {
        [timmer invalidate];
        self.getTelephoneCodeBtn.enabled = YES;
        [self.getTelephoneCodeBtn setTitle:@"发送验证码" forState:UIControlStateNormal];
        [self.getTelephoneCodeBtn setBackgroundColor:getColor(@"fa2671")];
        i = 29;
    }
}

 

发送短信验证码按钮 定时器

标签:短信验证码   nat   发送   scheduled   nslog   target   hone   bsp   timer   

原文地址:http://www.cnblogs.com/dujiahong/p/7407063.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!