[O] Combine reset and lap button
This commit is contained in:
@@ -283,7 +283,7 @@
|
|||||||
<rect key="frame" x="20" y="224.5" width="374" height="588.5"/>
|
<rect key="frame" x="20" y="224.5" width="374" height="588.5"/>
|
||||||
<subviews>
|
<subviews>
|
||||||
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" distribution="fillProportionally" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="4j4-zF-LWF">
|
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" distribution="fillProportionally" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="4j4-zF-LWF">
|
||||||
<rect key="frame" x="0.0" y="0.0" width="374" height="150"/>
|
<rect key="frame" x="0.0" y="0.0" width="374" height="70"/>
|
||||||
<subviews>
|
<subviews>
|
||||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Jse-AL-cOs">
|
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Jse-AL-cOs">
|
||||||
<rect key="frame" x="0.0" y="0.0" width="374" height="30"/>
|
<rect key="frame" x="0.0" y="0.0" width="374" height="30"/>
|
||||||
@@ -295,40 +295,20 @@
|
|||||||
<action selector="start:" destination="PYt-Lf-JNp" eventType="touchUpInside" id="ucf-fN-SgP"/>
|
<action selector="start:" destination="PYt-Lf-JNp" eventType="touchUpInside" id="ucf-fN-SgP"/>
|
||||||
</connections>
|
</connections>
|
||||||
</button>
|
</button>
|
||||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="O4A-eq-kEz">
|
|
||||||
<rect key="frame" x="0.0" y="40" width="374" height="30"/>
|
|
||||||
<color key="backgroundColor" name="AccentColor"/>
|
|
||||||
<state key="normal" title="Stop">
|
|
||||||
<color key="titleColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
|
||||||
</state>
|
|
||||||
<connections>
|
|
||||||
<action selector="stop:" destination="PYt-Lf-JNp" eventType="touchUpInside" id="ncg-GB-bAj"/>
|
|
||||||
</connections>
|
|
||||||
</button>
|
|
||||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Q7i-3U-NbI">
|
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Q7i-3U-NbI">
|
||||||
<rect key="frame" x="0.0" y="80" width="374" height="30"/>
|
<rect key="frame" x="0.0" y="40" width="374" height="30"/>
|
||||||
<color key="backgroundColor" name="AccentColor"/>
|
<color key="backgroundColor" name="AccentColor"/>
|
||||||
<state key="normal" title="Reset">
|
<state key="normal" title="Reset">
|
||||||
<color key="titleColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
<color key="titleColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||||
</state>
|
</state>
|
||||||
<connections>
|
<connections>
|
||||||
<action selector="reset:" destination="PYt-Lf-JNp" eventType="touchUpInside" id="3ff-of-rJl"/>
|
<action selector="lapOrReset:" destination="PYt-Lf-JNp" eventType="touchUpInside" id="3ff-of-rJl"/>
|
||||||
</connections>
|
|
||||||
</button>
|
|
||||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="794-VN-m96">
|
|
||||||
<rect key="frame" x="0.0" y="120" width="374" height="30"/>
|
|
||||||
<color key="backgroundColor" name="AccentColor"/>
|
|
||||||
<state key="normal" title="Lap">
|
|
||||||
<color key="titleColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
|
||||||
</state>
|
|
||||||
<connections>
|
|
||||||
<action selector="lap:" destination="PYt-Lf-JNp" eventType="touchUpInside" id="UT9-pP-BWA"/>
|
|
||||||
</connections>
|
</connections>
|
||||||
</button>
|
</button>
|
||||||
</subviews>
|
</subviews>
|
||||||
</stackView>
|
</stackView>
|
||||||
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="O7B-Tj-vT0">
|
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="O7B-Tj-vT0">
|
||||||
<rect key="frame" x="0.0" y="158" width="374" height="430.5"/>
|
<rect key="frame" x="0.0" y="78" width="374" height="510.5"/>
|
||||||
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
|
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
|
||||||
<prototypes>
|
<prototypes>
|
||||||
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="lapCell" id="2Je-Lw-ZAb">
|
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="lapCell" id="2Je-Lw-ZAb">
|
||||||
@@ -385,10 +365,8 @@
|
|||||||
</view>
|
</view>
|
||||||
<tabBarItem key="tabBarItem" title="Stopwatch" image="clock.arrow.circlepath" catalog="system" selectedImage="clock.arrow.circlepath" id="hNc-UI-vIQ"/>
|
<tabBarItem key="tabBarItem" title="Stopwatch" image="clock.arrow.circlepath" catalog="system" selectedImage="clock.arrow.circlepath" id="hNc-UI-vIQ"/>
|
||||||
<connections>
|
<connections>
|
||||||
<outlet property="lapButton" destination="794-VN-m96" id="1aX-pS-Cjr"/>
|
|
||||||
<outlet property="resetButton" destination="Q7i-3U-NbI" id="gYT-DB-XpP"/>
|
<outlet property="resetButton" destination="Q7i-3U-NbI" id="gYT-DB-XpP"/>
|
||||||
<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="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"/>
|
<outlet property="timeLabel" destination="55a-Ig-Fri" id="8eb-Ow-UF1"/>
|
||||||
</connections>
|
</connections>
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ class StopwatchViewController: UIViewController {
|
|||||||
|
|
||||||
@IBOutlet weak var startButton: UIButton!
|
@IBOutlet weak var startButton: UIButton!
|
||||||
@IBOutlet weak var resetButton: UIButton!
|
@IBOutlet weak var resetButton: UIButton!
|
||||||
@IBOutlet weak var lapButton: UIButton!
|
|
||||||
|
|
||||||
@IBOutlet weak var tableView: UITableView!
|
@IBOutlet weak var tableView: UITableView!
|
||||||
|
|
||||||
@@ -36,6 +35,7 @@ class StopwatchViewController: UIViewController {
|
|||||||
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(count), userInfo: nil, repeats: true)
|
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(count), userInfo: nil, repeats: true)
|
||||||
started = true
|
started = true
|
||||||
startButton.setTitle("Stop", for: .normal)
|
startButton.setTitle("Stop", for: .normal)
|
||||||
|
resetButton.setTitle("Lap", for: .normal)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -43,48 +43,50 @@ class StopwatchViewController: UIViewController {
|
|||||||
timer.invalidate()
|
timer.invalidate()
|
||||||
started = false
|
started = false
|
||||||
startButton.setTitle("Start", for: .normal)
|
startButton.setTitle("Start", for: .normal)
|
||||||
|
resetButton.setTitle("Reset", for: .normal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc fileprivate func count() {
|
@objc fileprivate func count()
|
||||||
|
{
|
||||||
|
// Add time (If it goes longer than 24 hours, the hour count should go to 25)
|
||||||
seconds += 1
|
seconds += 1
|
||||||
|
|
||||||
if seconds == 60 {
|
if seconds == 60
|
||||||
|
{
|
||||||
minutes += 1
|
minutes += 1
|
||||||
seconds = 0
|
seconds = 0
|
||||||
}
|
}
|
||||||
if minutes == 60 {
|
if minutes == 60
|
||||||
|
{
|
||||||
hours += 1
|
hours += 1
|
||||||
minutes = 0
|
minutes = 0
|
||||||
}
|
}
|
||||||
if hours == 24 {
|
|
||||||
resetTimes()
|
|
||||||
}
|
|
||||||
|
|
||||||
timeLabel.text = String(format: "%02i:%02i:%02i", hours, minutes, seconds)
|
timeLabel.text = String(format: "%02i:%02i:%02i", hours, minutes, seconds)
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func reset(_ sender: UIButton) {
|
/**
|
||||||
resetTimes()
|
Lap/reset button
|
||||||
}
|
*/
|
||||||
|
@IBAction func lapOrReset(_ sender: UIButton)
|
||||||
func resetTimes() {
|
{
|
||||||
seconds = 0
|
if started
|
||||||
minutes = 0
|
{
|
||||||
seconds = 0
|
// Insert lap
|
||||||
lappedTimes = []
|
lappedTimes.insert(timeLabel.text!, at: 0)
|
||||||
timer.invalidate()
|
tableView.reloadData()
|
||||||
timeLabel.text = "00:00:00"
|
}
|
||||||
tableView.reloadData()
|
else
|
||||||
//startButton.isHidden = false
|
{
|
||||||
//lapButton.isHidden = true
|
// Reset
|
||||||
}
|
seconds = 0
|
||||||
|
minutes = 0
|
||||||
@IBAction func lap(_ sender: UIButton) {
|
seconds = 0
|
||||||
lappedTimes.append(String(format: "%02i:%02i:%02i", hours, minutes, seconds))
|
lappedTimes = []
|
||||||
|
timeLabel.text = "00:00:00"
|
||||||
let indexPath = IndexPath(row: lappedTimes.count - 1, section: 0)
|
tableView.reloadData()
|
||||||
tableView.insertRows(at: [indexPath], with: .automatic)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user