标签:and 方法 type 解决 turn send tar reserve mic
首先,有各种版本
方法一:
我运用的一种极其简单的版本: 将UIButton的Type 设成 Custom 就不会有闪烁的问题重现
@property (strong, nonatomic) IBOutlet UIButton *getCodeBtn;
@property (nonatomic, strong) NSTimer *timerCode; //验证码定时器
__block int leftTime;
- (void)dealloc {
if ([_timerCode isValid]) {
[_timerCode invalidate];
_timerCode = nil;
}
}
#pragma mark - 验证码
//重新发送验证码
- (IBAction)resendCodeBtnPressed:(UIButton *)sender {
//判断哪一个网络请求发送验证码
//...
sender.enabled = NO;
leftTime = 60;
[self startOneTimer];
//发送验证码请求
[self.viewModel requestWithSendCode:[kUSERDEFAULT objectForKey:_isResetPassword? kForgetMobile:kLoginMobile] block:^(BOOL flag) {
}];
}
/**
* 发送验证码之后等待若干时间
*/
- (void)startOneTimer {
_getCodeBtn.enabled = NO;
leftTime = 60;
_timerCode = [NSTimer scheduledTimerWithTimeInterval:1 block:^{
if (leftTime == 0) {
_getCodeBtn.enabled = YES;
[_getCodeBtn setTitle:@"重新发送" forState:UIControlStateNormal];
[_getCodeBtn setTitleColor:fcc639 forState:UIControlStateNormal];
//计时完成,销毁定时器
[_timerCode invalidate];
_timerCode = nil;
leftTime = 60;
return ;
}
leftTime--;
[_getCodeBtn setTitle:[NSString stringWithFormat:@"%i秒后重发", leftTime] forState:UIControlStateNormal];
[_getCodeBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
} repeats:YES];
}
方法二: 就是在UIButton上罩一个同样大小的UILabel,然后每次刷新UILabel的文字,不刷新按钮,效果不错,不再闪烁了
链接 :http://blog.csdn.net/kyfxbl/article/details/17619221
方法三:https://www.cnblogs.com/manji/p/4813520.html
补充: 我的方法中运用了 防止timer没有被销毁掉的timerBlocks 请自行查找
// NSTimer+Blocks.h
//
// Created by Jiva DeVoe on 1/14/11.
// Copyright 2011 Random Ideas, LLC. All rights reserved.
验证码计时 -- UIButton setTitle 闪烁问题解决方案
标签:and 方法 type 解决 turn send tar reserve mic
原文地址:http://www.cnblogs.com/Jenaral/p/6269007.html