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

实现短信倒计时

时间:2016-08-31 13:51:28      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:

@implementation ForgetViewController {
    
    __strong NSTimer * timer;
    NSInteger          secondes;
    
    
}
- (void)dealloc{
    
    if(timer != nil){
        [timer invalidate];
        timer = nil;
    }
}



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--;
}

 

实现短信倒计时

标签:

原文地址:http://www.cnblogs.com/ningmengcao-ios/p/5825534.html

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