查看NSTimer是一种简单的方法.可能不是最准确但相对简单. NSTimer每秒调用函数“update”(由1.0作为第一个参数表示)
var count = 300
override func viewDidLoad() {
super.viewDidLoad()
var timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: Selector("update"), userInfo: nil, repeats: true)
}
func update() {
if(count > 0){
let minutes = String(count / 60)
let seconds = String(count % 60)
countDownLabel.text = minutes + ":" + seconds
count--
}
}
网友评论