美文网首页
实现短信倒计时

实现短信倒计时

作者: 啊哈哈哈哈哈群 | 来源:发表于2016-10-25 11:52 被阅读42次

    @implementation ForgetViewController {

    __strong NSTimer * timer;

    NSInteger          secondes;

    }

    - (void)dealloc{

    if(timer != nil){

    [timer invalidate];

    timer = nil;

    }

    }

    - (void)btnClick:(UIButton *)sender {

    secondes= 59;

    if (!timer) {

    timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerFired:) userInfo:nil repeats:YES];

    [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];

    [timer fire];

    }

    -(void)timerFired:(id) sender

    {

    if(secondes <=0) {

    self.codeBtn.enabled = YES;

    [self.codeBtn setTitle:@"重新获取" forState:UIControlStateNormal];

    } else {

    NSString * title = [NSString stringWithFormat:@"(%lds)后重发", secondes];

    [self.codeBtn setTitle:title forState:UIControlStateNormal];

    }

    secondes--;

    }

    相关文章

      网友评论

          本文标题:实现短信倒计时

          本文链接:https://www.haomeiwen.com/subject/bferuttx.html