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)文章
RxSwift學(xué)習(xí)之Observable的新建、訂閱及取消訂閱
這篇文章主要給大家介紹了關(guān)于RxSwift學(xué)習(xí)教程之Observable的相關(guān)資料,文中詳細(xì)的給大家介紹了關(guān)于新建Observable、訂閱Observable和取消訂閱并消除內(nèi)存泄漏等相關(guān)的內(nèi)容,需要的朋友可以參考借鑒,下面來一起看看吧。2017-09-09
Swift內(nèi)置的數(shù)字類型及基本的轉(zhuǎn)換方法
這篇文章主要介紹了Swift內(nèi)置的數(shù)字類型及基本的轉(zhuǎn)換方法,是Swift入門學(xué)習(xí)中的基礎(chǔ)知識,需要的朋友可以參考下2015-11-11
Swift利用指紋識別或面部識別為應(yīng)用添加私密保護功能
這篇文章主要給大家介紹了關(guān)于Swift利用指紋識別或面部識別為應(yīng)用添加私密保護功能的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用swift具有一定的參考學(xué)習(xí)價值,需要的朋友下面隨著小編來一起看看吧2018-05-05

