iOS经典讲解之倒计时按钮JKCountDownButton的使用

来源:互联网 发布:java窗口程序实例 编辑:程序博客网 时间:2024/05/22 04:27

作者:Loving_iOS

转载请标明出处:http://blog.csdn.net/loving_ios/article/details/50786890

下载倒计时按钮JKCountDownButton 代码传送门

JKCountDownButton,实现iOS倒计时按钮,常用于注册等发送验证码的时候进行倒计时操作。

下面介绍其用法:

代码方式创建:

JKCountDownButton *button = [JKCountDownButton buttonWithType:UIButtonTypeCustom];button.frame = CGRectMake(100, 100, 100, 100);[button setTitle:@"获取验证码" forState:UIControlStateNormal];button.backgroundColor = [UIColor blueColor];[self.view addSubview:button]; [button addToucheHandler:^(JKCountDownButton*sender, NSInteger tag) {    sender.enabled = NO;     [sender startWithSecond:10.0];     [sender didChange:^NSString *(JKCountDownButton *countDownButton,int second) {        NSString *title = [NSString stringWithFormat:@"剩余%d秒",second];        return title;    }];    [sender didFinished:^NSString *(JKCountDownButton *countDownButton, int second) {        countDownButton.enabled = YES;        return @"点击重新获取";     }]; }];
用拖控件方式创建:首先你要button继承JKCountDownButton类,type 设置成custom
@property (weak, nonatomic) IBOutlet JKCountDownButton *button; - (IBAction)countDown:(JKCountDownButton*)sender {sender.enabled = NO;//button type要 设置成custom 否则会闪动[sender startWithSecond:10.0]; [sender didChange:^NSString *(JKCountDownButton *countDownButton,int second) {    NSString *title = [NSString stringWithFormat:@"剩余%d秒",second];    return title;}];[sender didFinished:^NSString *(JKCountDownButton *countDownButton, int second) {    countDownButton.enabled = YES;    return @"点击重新获取"; }];}

效果图:


1 0
原创粉丝点击