[O] Make start/stop one button

This commit is contained in:
Hykilpikonna
2021-01-24 08:56:54 -05:00
parent 606461d75a
commit 419726f94e
+20 -16
View File
@@ -12,7 +12,6 @@ class StopwatchViewController: UIViewController {
@IBOutlet weak var timeLabel: UILabel! @IBOutlet weak var timeLabel: UILabel!
@IBOutlet weak var startButton: UIButton! @IBOutlet weak var startButton: UIButton!
@IBOutlet weak var stopButton: UIButton!
@IBOutlet weak var resetButton: UIButton! @IBOutlet weak var resetButton: UIButton!
@IBOutlet weak var lapButton: UIButton! @IBOutlet weak var lapButton: UIButton!
@@ -21,20 +20,30 @@ class StopwatchViewController: UIViewController {
var hours = 0 var hours = 0
var minutes = 0 var minutes = 0
var seconds = 0 var seconds = 0
var started = false
var lappedTimes: [String] = [] var lappedTimes: [String] = []
var timer = Timer() var timer = Timer()
override func viewDidLoad() { /**
super.viewDidLoad() Start/stop stopwatch
*/
//lapButton.isHidden = true @IBAction func start(_ sender: UIButton)
} {
if !started
@IBAction func start(_ sender: UIButton) { {
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(count), userInfo: nil, repeats: true) // Start timer
//startButton.isHidden = true timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(count), userInfo: nil, repeats: true)
//lapButton.isHidden = false started = true
startButton.setTitle("Stop", for: .normal)
}
else
{
// Stop timer
timer.invalidate()
started = false
startButton.setTitle("Start", for: .normal)
}
} }
@objc fileprivate func count() { @objc fileprivate func count() {
@@ -55,11 +64,6 @@ class StopwatchViewController: UIViewController {
timeLabel.text = String(format: "%02i:%02i:%02i", hours, minutes, seconds) timeLabel.text = String(format: "%02i:%02i:%02i", hours, minutes, seconds)
} }
@IBAction func stop(_ sender: UIButton) {
timer.invalidate()
//startButton.isHidden = false
}
@IBAction func reset(_ sender: UIButton) { @IBAction func reset(_ sender: UIButton) {
resetTimes() resetTimes()
} }