实现短信倒计时
Posted _水畔竹汐
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了实现短信倒计时相关的知识,希望对你有一定的参考价值。
@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--; }
以上是关于实现短信倒计时的主要内容,如果未能解决你的问题,请参考以下文章