代码库> 刷新控件> 验证码倒计时
验证码倒计时
上传者:紫_川 分类:刷新控件(Refresh Control)
查看次数:979 下载次数:0
上传时间:2015-09-04 大小:
验证码 NSTimer   60秒刷新 ,禁用button




//
//  ViewController.m
//  AutoCode-01
//
//  Created by Apple on 15/9/4.
//  Copyright (c) 2015年 Sayimo. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
{
    NSInteger secondsCountDown;
    NSTimer * countDownTimer;
    __weak IBOutlet UIButton *autoCodeButton;
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    secondsCountDown=60;
}

- (IBAction)autoCode:(UIButton *)sender {
    secondsCountDown=60;
    [autoCodeButton setTitle:[NSString stringWithFormat:@"%zd",secondsCountDown] forState:UIControlStateNormal];
    countDownTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeFireMethod) userInfo:nil repeats:YES];
    autoCodeButton.enabled=NO;
}

-(void)timeFireMethod{
    secondsCountDown--;
    [autoCodeButton setTitle:[NSString stringWithFormat:@"%zd",secondsCountDown] forState:UIControlStateNormal];
    if (secondsCountDown<0) {
        [countDownTimer invalidate];
        autoCodeButton.enabled=YES;
        [autoCodeButton setTitle:@"获取验证码" forState:UIControlStateNormal];

    }
}

@end

收藏
我来说两句
发表评论
您还没有登录!请登录注册
所有评论(0
下载过该代码的还下载了
综合评论
sina weixin mail 回到顶部