在app 注冊(cè)或者登錄 需要驗(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í)功能,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)VEVB武林網(wǎng)網(wǎng)站的支持!
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注