iOS开发中,有一个验证码倒计时的场景,实现起来不困难,但做完之后会发现一个很奇怪的现象,每秒闪烁一下,让人很烦,如果不希望这个效果,很简单, 把UIButton的Type 设置成Custom 就可以了!
验证码倒计时
self.timer=[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(CountTime) userInfo:nil repeats:YES];
/**
* 验证码倒计时
*/
-(void)CountTime{
if (self.countdownnumber>=0)
{
NSString *str=[NSString stringWithFormat:@"%d秒",self.countdownnumber];
[self.getCaptchaButton setTitle:str forState:UIControlStateNormal];
self.countdownnumber--;
}
else
{
[self.timer invalidate];
self.getCaptchaButton.userInteractionEnabled=YES;
self.getCaptchaButton.backgroundColor = BTN_YES_COLOR;
[self.getCaptchaButton setTitle:@"获取验证码" forState:UIControlStateNormal];
}
}