0
私は最近、ストックiOSデバイスのストップウォッチアプリに似ているストップウォッチアプリを作っています。私はタイマーを稼働させているが、アップルが持っているストップウォッチのように、同じ外観と正確な時間を守ってほしい。今のところ、私は秒を示しています。私が知っていることについては、数字を00:00.00の形式に変換する必要があります。ストップウォッチで正確な時刻を表示するには?
import UIKit
class ViewController: UIViewController {
var counter = 0
var timer = Timer()
@IBOutlet weak var timerLbl: UILabel!
@IBAction func startBtn(sender: Any) {
timer.invalidate()
timer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(ViewController.updateTimer), userInfo: nil, repeats: true)
}
@IBAction func stopBtn(sender: Any) {
timer.invalidate()
counter = 0
}
func updateTimer() {
counter += 1
timerLbl.text = "(counter)"
}
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.
}
}
[iPhoneの日付文字列の何ミリ秒のフォーマット文字列ですか?](https://stackoverflow.com/questions/6456626/what-format-文字列を使ってi-use-for-milliseconds-in-iphone) – Wukerplank
@WukerplankはObjective-Cのためのもので、Swiftの答えを探しています。 – Dexter
あなたは冗談でなければなりません。 'NSDateFormatter'のドキュメンテーションを探し、提供された答えの書式文字列を使用してください。 – Wukerplank