美文网首页
iOS swift-倒计时

iOS swift-倒计时

作者: 青菜白玉堂 | 来源:发表于2017-06-21 16:41 被阅读43次

    var daojishiTimer:Timer!

    var daojishi = 4

    func daoJiShi() -> () {

    // 启用计时器,控制每秒执行一次tickDown方法

    daojishiTimer = Timer.scheduledTimer(timeInterval: 1,

    target:self,selector:#selector(tickDown),

    userInfo:nil,repeats:true)

    }

    /**

    *计时器每秒触发事件

    **/

    func tickDown()

    {

    daojishi -= 1

    if daojishi == 0 {

    self.linshiSaoBtn.setTitleColor(btnBgColor, for: .normal)

    self.linshiSaoBtn.setTitle("开锁", for: .normal)

    self.kaiSuoImg.image = UIImage.init(named:"lALO2gyzUSQk")

    self.kaisuoBeiJinBtn.isEnabled = true

    self.linshiSaoBtn.isEnabled = true

    //停止定时器

    daojishiTimer.invalidate()

    }else{

    self.linshiSaoBtn.setTitleColor(UIColor.gray, for: .normal)

    self.linshiSaoBtn.setTitle("\(daojishi)", for: .normal)

    self.kaiSuoImg.image = UIImage.init(named:"lALO2gyzUSQk")

    }

    }

    //参考:http://blog.csdn.net/qq_29846663/article/details/54667961

    相关文章

      网友评论

          本文标题:iOS swift-倒计时

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