欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

iOS 驗(yàn)證碼按鈕倒計(jì)時(shí)功能

 更新時(shí)間:2017年07月27日 09:09:30   作者:鴻鵠當(dāng)高遠(yuǎn)  
在app注冊(cè)或者登錄需要驗(yàn)證碼的地方、為了避免短時(shí)間內(nèi)刷驗(yàn)證碼、往往會(huì)加上一層驗(yàn)證當(dāng)?shù)褂?jì)時(shí)結(jié)束后、可以重新獲取,關(guān)于ios 驗(yàn)證碼按鈕倒計(jì)時(shí)功能大家可以參考下本文

在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ì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論