您的位置:首页 > 移动开发 > IOS开发

iOS开发NSTimer闪烁问题

2016-01-05 19:23 501 查看
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];
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: