[O] Optimize stopwatch implementation
This commit is contained in:
@@ -360,8 +360,8 @@
|
|||||||
<nil key="highlightedColor"/>
|
<nil key="highlightedColor"/>
|
||||||
</label>
|
</label>
|
||||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="00:00:00" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="55a-Ig-Fri" customClass="StopwatchText" customModule="ProjectClock" customModuleProvider="target">
|
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="00:00:00" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="55a-Ig-Fri" customClass="StopwatchText" customModule="ProjectClock" customModuleProvider="target">
|
||||||
<rect key="frame" x="52.5" y="109" width="309" height="95.5"/>
|
<rect key="frame" x="51" y="109" width="312.5" height="95.5"/>
|
||||||
<fontDescription key="fontDescription" type="system" weight="ultraLight" pointSize="80"/>
|
<fontDescription key="fontDescription" type="system" weight="thin" pointSize="80"/>
|
||||||
<nil key="textColor"/>
|
<nil key="textColor"/>
|
||||||
<nil key="highlightedColor"/>
|
<nil key="highlightedColor"/>
|
||||||
</label>
|
</label>
|
||||||
@@ -390,6 +390,7 @@
|
|||||||
<outlet property="startButton" destination="Jse-AL-cOs" id="iq2-xE-Nir"/>
|
<outlet property="startButton" destination="Jse-AL-cOs" id="iq2-xE-Nir"/>
|
||||||
<outlet property="stopButton" destination="O4A-eq-kEz" id="dd7-v0-fqc"/>
|
<outlet property="stopButton" destination="O4A-eq-kEz" id="dd7-v0-fqc"/>
|
||||||
<outlet property="tableView" destination="O7B-Tj-vT0" id="kfu-vG-sgE"/>
|
<outlet property="tableView" destination="O7B-Tj-vT0" id="kfu-vG-sgE"/>
|
||||||
|
<outlet property="timeLabel" destination="55a-Ig-Fri" id="8eb-Ow-UF1"/>
|
||||||
</connections>
|
</connections>
|
||||||
</viewController>
|
</viewController>
|
||||||
<placeholder placeholderIdentifier="IBFirstResponder" id="ZlX-5W-Pjn" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
|
<placeholder placeholderIdentifier="IBFirstResponder" id="ZlX-5W-Pjn" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
|
||||||
|
|||||||
@@ -9,9 +9,7 @@ import UIKit
|
|||||||
|
|
||||||
class StopwatchViewController: UIViewController {
|
class StopwatchViewController: UIViewController {
|
||||||
|
|
||||||
@IBOutlet weak var hourLabel: UILabel!
|
@IBOutlet weak var timeLabel: UILabel!
|
||||||
@IBOutlet weak var minuteLabel: UILabel!
|
|
||||||
@IBOutlet weak var secondLabel: UILabel!
|
|
||||||
|
|
||||||
@IBOutlet weak var startButton: UIButton!
|
@IBOutlet weak var startButton: UIButton!
|
||||||
@IBOutlet weak var stopButton: UIButton!
|
@IBOutlet weak var stopButton: UIButton!
|
||||||
@@ -54,12 +52,7 @@ class StopwatchViewController: UIViewController {
|
|||||||
resetTimes()
|
resetTimes()
|
||||||
}
|
}
|
||||||
|
|
||||||
if seconds >= 10 { secondLabel.text = "\(seconds)" }
|
timeLabel.text = String(format: "%02i:%02i:%02i", hours, minutes, seconds)
|
||||||
else { secondLabel.text = "0\(seconds)" }
|
|
||||||
if minutes >= 10 { minuteLabel.text = "\(minutes)" }
|
|
||||||
else { minuteLabel.text = "0\(minutes)" }
|
|
||||||
if hours >= 10 { hourLabel.text = "\(hours)" }
|
|
||||||
else { hourLabel.text = "0\(hours)" }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func stop(_ sender: UIButton) {
|
@IBAction func stop(_ sender: UIButton) {
|
||||||
@@ -77,29 +70,14 @@ class StopwatchViewController: UIViewController {
|
|||||||
seconds = 0
|
seconds = 0
|
||||||
lappedTimes = []
|
lappedTimes = []
|
||||||
timer.invalidate()
|
timer.invalidate()
|
||||||
secondLabel.text = "00"
|
timeLabel.text = "00:00:00"
|
||||||
minuteLabel.text = "00"
|
|
||||||
hourLabel.text = "00"
|
|
||||||
tableView.reloadData()
|
tableView.reloadData()
|
||||||
//startButton.isHidden = false
|
//startButton.isHidden = false
|
||||||
//lapButton.isHidden = true
|
//lapButton.isHidden = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func lap(_ sender: UIButton) {
|
@IBAction func lap(_ sender: UIButton) {
|
||||||
var currentSec = ""
|
lappedTimes.append(String(format: "%02i:%02i:%02i", hours, minutes, seconds))
|
||||||
if seconds >= 10 { currentSec = "\(seconds)" }
|
|
||||||
else { currentSec = "0\(seconds)" }
|
|
||||||
|
|
||||||
var currentMin = ""
|
|
||||||
if minutes >= 10 { currentMin = "\(minutes)" }
|
|
||||||
else { currentMin = "0\(minutes)" }
|
|
||||||
|
|
||||||
var currentHour = ""
|
|
||||||
if hours >= 10 { currentHour = "\(hours)" }
|
|
||||||
else { currentHour = "0\(hours)" }
|
|
||||||
|
|
||||||
let currentTime = "\(currentHour):\(currentMin):\(currentSec)" //CHECK THIS
|
|
||||||
lappedTimes.append(currentTime)
|
|
||||||
|
|
||||||
let indexPath = IndexPath(row: lappedTimes.count - 1, section: 0)
|
let indexPath = IndexPath(row: lappedTimes.count - 1, section: 0)
|
||||||
tableView.insertRows(at: [indexPath], with: .automatic)
|
tableView.insertRows(at: [indexPath], with: .automatic)
|
||||||
|
|||||||
Reference in New Issue
Block a user