iOS定时刷新按钮的文字,避免按钮闪烁的办法
2016-08-10 17:24
295 查看
http://blog.csdn.net/lvxiangan/article/details/49276981
今天做一个功能,一开始将某按钮置灰,然后倒计时60秒。每秒钟都刷新按钮的文字,倒计时结束后,使按钮可用。很快就做好了,不过发现一个问题,就是按钮会闪烁,跟星星似的。我的代码是:
解决方法:
将UIButton的类型由system改为custom就OK
今天做一个功能,一开始将某按钮置灰,然后倒计时60秒。每秒钟都刷新按钮的文字,倒计时结束后,使按钮可用。很快就做好了,不过发现一个问题,就是按钮会闪烁,跟星星似的。我的代码是:
_countDown = 60; UIColor *color = self.canSend ? [UIColor colorWithRed:40.0/255.0 green:90.0/255.0f blue:190.0/255.0f alpha:1.0f] : [UIColor grayColor]; self.smsButton = [UIButton createButtonWithStyle:UIButtonTypeRoundedRect withFrame:CGRectMake(80, 0, 100, 30) withTitle:NSLocalizedString(@"重发验证码", nil) withTitleColor:color withBackgroudColor:nil withNormalImage:nil withHighlightedImage:nil withNormalBackgroudImage:nil withHighlightedBackgroundImage:nil withTarge:self withAction:@selector(startTimer:) actionHandle:^(UIButton *sender) { }];
- (void)startTimer { [self.smsButton setEnabled:NO]; _timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(onTimer) userInfo:nil repeats:YES]; } - (void)onTimer { if (_countDown > 0) { [self.smsButton setTitle:[NSString stringWithFormat:@"%d秒重新获取", _countDown] forState:UIControlStateDisabled]; _countDown--; } else { _countDown = 60; [_timer invalidate]; _timer = nil; [self.smsButton setTitle:@"60秒重新获取" forState:UIControlStateDisabled]; [self.smsButton setTitle:@"重发验证码" forState:UIControlStateNormal]; [self.smsButton setEnabled:YES]; } }
解决方法:
将UIButton的类型由system改为custom就OK
相关文章推荐
- iOS之用NSTimer定时刷新按钮的文字,避免按钮闪烁的办法
- 用NSTimer定时刷新按钮的文字,避免按钮闪烁的办法
- iOS使用GCD或NSTimer定时刷新按钮的文字,按钮文字闪烁的问题
- iOS 做验证码发送 定时器 避免按钮闪烁
- 用ajax技术实现无闪烁定时刷新页面
- 避免刷新页面,自动跳回到页面顶部的办法
- 双缓冲避免刷新时的闪烁
- 防止刷新时闪烁的终极解决办法
- Adobe Photoshop CS3 输入文字不显示(不自动刷新)解决办法
- IOS第十七天——写一个基本的点击按钮更换Label文字的App
- input文本框、文字、按钮、图片 垂直居中对齐的解决办法
- 定时刷新页面时不让页面闪烁
- ios 防止按钮快速点击造成多次响应的避免方法。
- 对话框滚动时刷新自绘文字很乱解决办法
- 用ajax技术实现无闪烁定时刷新页面
- IOS开发之UIButton同时设置图片文字以及出发按钮时文字图片的切换
- 避免刷新页面,自动跳回到页面顶部的办法
- 如何避免treeview控件闪烁刷新
- 浏览器上的按钮文字特别小 之解决办法
- UIAlertView 类用法汇总(1):简单显示;多行按钮;定时消除alert;录入文字