首页 > 学院 > 开发设计 > 正文

递归实现倒计时

2019-11-08 00:04:01
字体:
来源:转载
供稿:网友

//开始倒计时

    func doCoundDown(btnrengou:BFPaperButton,curtime:Int,cdIndex:Int) {

        

        NSTimer.after(1.0.seconds) {

            objc_sync_enter(self)

            if(cdIndex ==self.resetCount){

                

                let cutimestr =String(format: "%d", curtime);

                //剩余时间(给cell里的label赋值)

                btnrengou.setTitle(XCTools().PRoductTimeDown(cutimestr), forState: .Normal)

                btnrengou.backgroundColor =UIColor.grayColor()

                btnrengou.enabled =false

                if(curtime>0)

                {

                    //显示下一秒

                    self.doCoundDown(btnrengou,curtime:Int(curtime - 1),cdIndex: cdIndex);

                }else{

                    btnrengou.setTitle("立即认购", forState: .Normal)

                    btnrengou.backgroundColor =KEY_COLOR_NAV

                    btnrengou.enabled =true

                }

            }

            objc_sync_exit(self)

        }

        

    }


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表