swift 3.0 實現(xiàn)短信驗證碼倒計時功能
更新時間:2017年02月23日 15:04:07 作者:qq_25592881
這篇文章主要介紹了swift 3.0 實現(xiàn)短信驗證碼倒計時功能的相關資料,需要的朋友可以參考下
下面一段代碼給大家分享swift 3.0 實現(xiàn)短信驗證碼倒計時功能,具體實例代碼如下所示:
class TCCountDown {
private var countdownTimer: Timer?
var codeBtn = UIButton()
private var remainingSeconds: Int = 0 {
willSet {
codeBtn.setTitle("重新獲取\(newValue)秒", for: .normal)
if newValue <= 0 {
codeBtn.setTitle("獲取驗證碼", for: .normal)
isCounting = false
}
}
}
var isCounting = false {
willSet {
if newValue {
countdownTimer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(self.updateTime), userInfo: nil, repeats: true)
remainingSeconds = 60
codeBtn.setTitleColor(BtnCodeColor, for: .normal)
} else {
countdownTimer?.invalidate()
countdownTimer = nil
codeBtn.setTitleColor(MainColor, for: .normal)
}
codeBtn.isEnabled = !newValue
}
}
@objc private func updateTime() {
remainingSeconds -= 1
}
}
//調用方法
var countDown = TCCountDown()//實例化
countDown.isCounting = true//開啟倒計時
以上所述是小編給大家介紹的swift 3.0 實現(xiàn)短信驗證碼倒計時功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網站的支持!
相關文章
詳解在swift中實現(xiàn)NSCoding的自動歸檔和解檔
本篇文章主要介紹了在swift中實現(xiàn)NSCoding的自動歸檔和解檔,具有一定的參考價值,感興趣的小伙伴們可以參考一下。2017-03-03
Swift利用CoreData實現(xiàn)一個通訊錄存儲詳解
這篇文章主要給大家介紹了關于Swift利用CoreData實現(xiàn)一個通訊錄存儲的相關資料,本文是大家學習coreDate的基礎問題,文中通過示例代碼介紹的非常詳細,需要的朋友可以參考借鑒,下面隨著小編來一起學習學習吧。2017-12-12

