美文网首页
Swift 获取手机验证码倒计时效果

Swift 获取手机验证码倒计时效果

作者: 咸鱼有只喵 | 来源:发表于2018-05-08 13:40 被阅读24次
        
        
        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 获取手机验证码倒计时效果

          本文链接:https://www.haomeiwen.com/subject/qtoirftx.html