1
你好我正在開發一個倒數計時器,它必須在8小時後停止。那就是:如何使用Swift做CountDown計時器
import UIKit
class ViewController: UIViewController {
var timer = NSTimer()
var counter = 0
@IBOutlet weak var Label: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func Start(sender: AnyObject) {
counter = 28800
Label.text = String(counter)
timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("updateTimer"), userInfo: nil, repeats: true)
}
func updateTimer() {
counter -= 1
Label.text = String(counter)
}
@IBAction func Stop(sender: AnyObject) {
timer.invalidate()
}
}
但有28800秒(這是8小時)我想顯示08:00:00,07:59:59,七點59分58秒,等等...代替目前它正在顯示28800,2899,28798等。你有一個想法如何格式化爲一個真正的時鐘(08:00:00)?