IOS verification code button countdown, ios Verification Code
Verification code is often added to the app registration or login, to avoid refreshing the verification code in a short period of time.
After the countdown is over, you can get it again!
The code is implemented as follows:
// _ CountdownTime: Total countdown time;
// _ Timer
-(Void) startTime :( UIButton *) VerificationCodeButton {_ block NSInteger timeout = [_ CountdownTime integerValue]; queue = hour (hour, 0); _ timer = dispatch_source_create (hour, 0, 0, queue); dispatch_source_set_timer (_ timer, dispatch_walltime (NULL, 0), 1.0 * NSEC_PER_SEC, 0); hour (_ timer, ^ {if (timeout <= 0) {dispatch_source_cancel (_ timer); dispatch_async (dispatch_get_main_queue (), ^ {[VerificationCodeButton setTitle: @ "get" 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 );}