Verification code Timing--UIButton settitle flicker Problem Solution

Source: Internet
Author: User

First, there are various versions

Method One:

An extremely simple version of my application: Setting the type of UIButton to Custom will not reproduce the problem of flicker

@property (strong, nonatomic) iboutlet UIButton *getcodebtn;

@property (nonatomic, strong) Nstimer *timercode; // Verification Code timer

__block int lefttime;

-(void) dealloc {

if ([_timercode isValid]) {

[_timercode invalidate];

_timercode = nil;

}

}

#pragma mark-Verification code

Resend Verification Code

-(ibaction) resendcodebtnpressed: (UIButton *) Sender {

// determine which network request to send a verification code

//...

Sender. enabled = NO;

lefttime = ;

[self startonetimer];

// Send verification code request

[self. ViewModel requestwithsendcode: [kuserdefault objectforkey:_isresetpassword ? kforgetmobile:kloginmobile] block: ^ (BOOL flag) {

}];

}

/**

* wait some time after sending verification code

*/

-(void) Startonetimer {

_getcodebtn. Enabled = NO;

lefttime = ;

_timercode = [nstimer scheduledtimerwithtimeinterval:1 block: ^{

if (lefttime = = 0) {

_getcodebtn. Enabled = YES;

[_getcodebtn settitle:" resend " forstate: UIControlStateNormal];

[_getcodebtn settitlecolor:fcc639 forstate:uicontrolstatenormal];

// timer complete, destroy timer

[_timercode invalidate];

_timercode = nil;

lefttime = ;

return ;

}

lefttime--;

        [_getcodebtn settitle:[nsstring Stringwithformat:@ "%i seconds after re-sending lefttime] forstate:uicontrolstatenormal

[_getcodebtn settitlecolor: [uicolor lightgraycolor] forstate: UIControlStateNormal];

} repeats:YES];

}

Method Two: Is on the UIButton cover a same size uilabel, and then each time the Uilabel text refresh, do not refresh the button, the effect is good, no longer flashing

Links: http://blog.csdn.net/kyfxbl/article/details/17619221

Method Three: Https://www.cnblogs.com/manji/p/4813520.html

Add: My method uses to prevent the timer not to be destroyed the timerblocks please search by oneself

Nstimer+blocks.h

//

Created by Jiva DeVoe on 1/14/11.

Copyright: Random Ideas, LLC. All rights reserved.

Verification code Timing--UIButton settitle flicker Problem Solution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.