var countDownTime:Timer?
var remainSeconds: Int = 0{
willSet{
self.getCodeButton.setTitle("\(newValue)秒后重新获取", for: .normal)
self.getCodeButton.isEnabled = false
if newValue <= 0 {
self.getCodeButton.setTitle("重新获取", for: .normal)
self.getCodeButton.isEnabled = true
}
}
}
var isCounting = false{
willSet{
if newValue {
countDownTime = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(updateTime), userInfo: nil, repeats: true)
remainSeconds = 60
}
}
}
@objc func updateTime(_timer:Timer){
remainSeconds -= 1
}
Swift 获取手机验证码倒计时效果
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 效果图 issue: 在定时器中不断刷新设置button.setTitle时,button会出现闪烁的现象 解决:...