iOS 驗(yàn)證碼按鈕倒計(jì)時(shí)功能
在app 注冊或者登錄 需要驗(yàn)證碼的地方、為了避免短時(shí)間內(nèi)刷驗(yàn)證碼、往往會(huì)加上一層驗(yàn)證。

倒計(jì)時(shí)結(jié)束后、可以重新獲取!

代碼實(shí)現(xiàn)如下:
// _CountdownTime 倒計(jì)時(shí)總時(shí)間;
//_timer 定時(shí)器
- (void)startTime:(UIButton *)VerificationCodeButton
{
__block NSInteger timeout = [_CountdownTime integerValue];
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
_timer= dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0);
dispatch_source_set_event_handler(_timer, ^{
if(timeout<=0){
dispatch_source_cancel(_timer);
dispatch_async(dispatch_get_main_queue(), ^{
[VerificationCodeButton setTitle:@"重新獲取" forState:UIControlStateNormal];
VerificationCodeButton.userInteractionEnabled = YES;
VerificationCodeButton.alpha = 1.0;
VerificationCodeButton.backgroundColor = [UIColor whiteColor];
});
} else {
NSString *strTime = [NSString stringWithFormat:@"%lds", (long)timeout];
dispatch_async(dispatch_get_main_queue(), ^{
[VerificationCodeButton setTitle:strTime forState:UIControlStateNormal];
VerificationCodeButton.userInteractionEnabled = NO;
VerificationCodeButton.backgroundColor = [UIColor lightTextColor];
});
timeout--;
}
});
dispatch_resume(_timer);
}
總結(jié)
以上所述是小編給大家介紹的iOS 驗(yàn)證碼按鈕倒計(jì)時(shí)功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
iOS?實(shí)現(xiàn)類似抖音滾動(dòng)效果
這篇文章主要介紹了iOS?實(shí)現(xiàn)類似抖音滾動(dòng)效果,整體思路是我們將tableView 的contentinset設(shè)置為上面一個(gè)屏幕的高度,下面一個(gè)屏幕的高度,左右為0,這樣保證我們滾動(dòng)過去的時(shí)候2024-06-06
都是準(zhǔn)備好的內(nèi)容,需要的朋友可以參考下
iOS開發(fā)使用UITableView制作N級下拉菜單的示例
這篇文章主要介紹了iOS開發(fā)使用UITableView制作N級下拉菜單的示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-01-01
iOS從App跳轉(zhuǎn)至系統(tǒng)設(shè)置菜單各功能項(xiàng)的編寫方法講解
這篇文章主要介紹了iOS從App跳轉(zhuǎn)至系統(tǒng)設(shè)置菜單各功能項(xiàng)的編寫方法講解,示例代碼為傳統(tǒng)的Objective-C,需要的朋友可以參考下2016-04-04

