I've recently been working on making a Stopwatch app that is similar to the one on the stock iOS devices. I have the timer working but I would like it to follow the same look and exact time like the stopwatch Apple has. As of right now I have it just showing the seconds. For what I know there has to be some kind of to convert the numbers to the 00:00.00 format.
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.
}
}