Method One:
- (void) startcountdown{_seconds= -; NSString*STR = [NSString stringWithFormat:@"available for re-acquisition after%d seconds", _seconds]; [_btnverify settitle:str forstate:uicontrolstatedisabled]; [_btnverify.titlelabel setfont:[uifont systemfontofsize: A]]; [_btnverify Setenabled:no]; _clocktimer= [Nstimer timerwithtimeinterval:1target:self selector: @selector (onesec Ondpass) Userinfo:nil Repeats:yes]; [[Nsrunloop Mainrunloop] Addtimer:_clocktimer formode:nsdefaultrunloopmode];}- (void) onesecondpass{if(_seconds >0) {_seconds= _seconds-1; NSString*STR = [NSString stringWithFormat:@"available for re-acquisition after%d seconds", _seconds]; [_btnverify settitle:str forstate:uicontrolstatedisabled]; } Else{[_clocktimer invalidate]; _clocktimer=Nil; [_btnverify.titlelabel setfont:[uifont systemfontofsize: the]]; [_btnverify Setenabled:yes]; }}
Method 2:
-(void) starttime{__blockinttimeout= -;//Countdown Timedispatch_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);//executes per secondDispatch_source_set_event_handler (_timer, ^{ if(timeout<=0){//countdown end, closeDispatch_source_cancel (_timer); Dispatch_async (Dispatch_get_main_queue (),^{[_btnverify settitle:@"Resend Verification Code"Forstate:uicontrolstatenormal]; _btnverify.userinteractionenabled=YES; }); }Else{Dispatch_async (Dispatch_get_main_queue (),^{[UIView beginanimations:nil context:nil]; [UIView setanimationduration:1]; [_btnverify settitle:[nsstring stringWithFormat:@"%zd seconds after re-sending", timeout] forstate:uicontrolstatenormal]; [UIView commitanimations]; _btnverify.userinteractionenabled=NO; }); Timeout--; } }); Dispatch_resume (_timer);}
It is important to note that the type to get the Captcha button is set to Custom.
If the title that is set to System,button is followed by a beat, instead of just the number beat.
iOS Development Get Verification Code button read seconds effect