国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > iOS > 正文

iOS 驗證碼按鈕倒計時功能

2020-07-26 02:44:33
字體:
供稿:網(wǎng)友

在app 注冊或者登錄 需要驗證碼的地方、為了避免短時間內(nèi)刷驗證碼、往往會加上一層驗證。

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

代碼實現(xiàn)如下:

// _CountdownTime 倒計時總時間;//_timer 定時器- (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 驗證碼按鈕倒計時功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對武林網(wǎng)網(wǎng)站的支持!

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 益阳市| 大悟县| 呼伦贝尔市| 秦安县| 浦城县| 星子县| 昌图县| 抚顺县| 邛崃市| 太和县| 广宁县| 于都县| 太白县| 漾濞| 蓬莱市| 治多县| 河东区| 邓州市| 南京市| 白河县| 峡江县| 巩留县| 金沙县| 连平县| 花莲市| 中方县| 广宁县| 吉木萨尔县| 秀山| 南召县| 股票| 洪江市| 家居| 子洲县| 长葛市| 曲周县| 娄烦县| 莲花县| 宁远县| 建水县| 惠来县|