IOS倒計時按鈕:JKCountDownButton

jopen 9年前發布 | 29K 次閱讀 iOS開發 移動開發 JKCountDownButton

JKCountDownButton,子類化UIButton實現IOS倒計時按鈕,常常用于注冊等發送驗證碼的時候進行倒計時操作

代碼方式使用

JKCountDownButton *_countDownCode;
_countDownCode = [JKCountDownButton buttonWithType:UIButtonTypeCustom];
_countDownCode.frame = CGRectMake(81, 200, 108, 32);
[_countDownCode setTitle:@"開始" forState:UIControlStateNormal];
_countDownCode.backgroundColor = [UIColor blueColor];
[self.view addSubview:_countDownCode];

[_countDownCode addToucheHandler:^(JKCountDownButton*sender, NSInteger tag) {
    sender.enabled = NO;

    [sender startWithSecond:10];

    [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 @"點擊重新獲取";

    }];

}];

xib方式使用

@property (weak, nonatomic) IBOutlet JKCountDownButton *countDownXib;

- (IBAction)countDownXibTouched:(JKCountDownButton*)sender {
sender.enabled = NO;
//button type要 設置成custom 否則會閃動
[sender startWithSecond:10];

[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 @"點擊重新獲取";

}];}

IOS倒計時按鈕:JKCountDownButton

項目主頁:http://www.baiduhome.net/lib/view/home/1426237207638

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!