首页 > 代码库 > 实现短信倒计时
实现短信倒计时
@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--;}
实现短信倒计时
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。