swift 3.0 實現(xiàn)短信驗證碼倒計時功能
更新時間:2017年02月23日 15:04:07 作者:qq_25592881
這篇文章主要介紹了swift 3.0 實現(xiàn)短信驗證碼倒計時功能的相關(guā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
}
}
//調(diào)用方法
var countDown = TCCountDown()//實例化
countDown.isCounting = true//開啟倒計時
以上所述是小編給大家介紹的swift 3.0 實現(xiàn)短信驗證碼倒計時功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
詳解Swift語言的while循環(huán)結(jié)構(gòu)
這篇文章主要介紹了Swift語言的while循環(huán)結(jié)構(gòu),包括do...while循環(huán)的用法,需要的朋友可以參考下2015-11-11
詳解在swift中實現(xiàn)NSCoding的自動歸檔和解檔
本篇文章主要介紹了在swift中實現(xiàn)NSCoding的自動歸檔和解檔,具有一定的參考價值,感興趣的小伙伴們可以參考一下。2017-03-03
Swift利用CoreData實現(xiàn)一個通訊錄存儲詳解
這篇文章主要給大家介紹了關(guān)于Swift利用CoreData實現(xiàn)一個通訊錄存儲的相關(guān)資料,本文是大家學(xué)習(xí)coreDate的基礎(chǔ)問題,文中通過示例代碼介紹的非常詳細,需要的朋友可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2017-12-12
Swift map和filter函數(shù)原型基礎(chǔ)示例
這篇文章主要為大家介紹了Swift map和filter函數(shù)原型基礎(chǔ)示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-07-07

