溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

iOS 倒計時驗證碼

發(fā)布時間:2020-07-11 10:20:43 來源:網(wǎng)絡(luò) 閱讀:285 作者:大頭狼小鬼 欄目:移動開發(fā)

- (void)yourButtonTitleTime

{

    __block int timeout=60; //倒計時時間

    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

    dispatch_source_t _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); //每秒執(zhí)行

    dispatch_source_set_event_handler(_timer, ^{

        if(timeout<=0){ //倒計時結(jié)束,關(guān)閉

            dispatch_source_cancel(_timer);

            dispatch_async(dispatch_get_main_queue(), ^{

                //設(shè)置界面的按鈕顯示 根據(jù)自己需求設(shè)置

                verBut.userInteractionEnabled = YES;

            });

        }else{

            dispatch_async(dispatch_get_main_queue(), ^{

                //設(shè)置界面的按鈕顯示 根據(jù)自己需求設(shè)置

                

                [verBut setTitle:(timeout==0?@"重發(fā)":[NSString stringWithFormat:@"%d",timeout]) forState:UIControlStateNormal];

                verBut.userInteractionEnabled = timeout==0?YES:NO;

            });

            timeout--;

        }

    });

    dispatch_resume(_timer);

}


向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

ios
AI