Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timer and Progress Bar #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 65 additions & 29 deletions EggTimer/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14810.12" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17506" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina6_7" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14766.15"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17505"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand All @@ -12,17 +14,17 @@
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="EggTimer" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC" userLabel="Background View">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<rect key="frame" x="0.0" y="0.0" width="428" height="926"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" distribution="fillEqually" spacing="39" translatesAutoresizingMaskIntoConstraints="NO" id="wI6-ag-afn" userLabel="Vertical Stack View">
<rect key="frame" x="20" y="44" width="374" height="818"/>
<rect key="frame" x="20" y="44" width="388" height="848"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="9S4-l0-41N" userLabel="Title View">
<rect key="frame" x="0.0" y="0.0" width="374" height="246.5"/>
<rect key="frame" x="0.0" y="0.0" width="388" height="256.66666666666669"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="How do you like your eggs?" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="15" translatesAutoresizingMaskIntoConstraints="NO" id="XLm-5r-pSP" userLabel="Title Label">
<rect key="frame" x="0.0" y="0.0" width="374" height="246.5"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="How do you like your eggs?" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" minimumFontSize="15" translatesAutoresizingMaskIntoConstraints="NO" id="XLm-5r-pSP" userLabel="Title Label">
<rect key="frame" x="0.0" y="0.0" width="388" height="256.66666666666669"/>
<fontDescription key="fontDescription" type="system" pointSize="30"/>
<color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
Expand All @@ -36,19 +38,22 @@
</constraints>
</view>
<stackView opaque="NO" contentMode="scaleAspectFit" distribution="fillEqually" spacing="20" translatesAutoresizingMaskIntoConstraints="NO" id="wAa-qa-eeB" userLabel="Egg Stack View">
<rect key="frame" x="0.0" y="285.5" width="374" height="247"/>
<rect key="frame" x="0.0" y="295.66666666666663" width="388" height="256.66666666666663"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="YXP-iV-bgO" userLabel="Soft Egg View">
<rect key="frame" x="0.0" y="0.0" width="111.5" height="247"/>
<rect key="frame" x="0.0" y="0.0" width="116" height="256.66666666666669"/>
<subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="soft_egg" translatesAutoresizingMaskIntoConstraints="NO" id="88O-7T-MuC" userLabel="Soft Egg ImageView">
<rect key="frame" x="0.0" y="0.0" width="116" height="256.66666666666669"/>
</imageView>
<button opaque="NO" contentMode="scaleAspectFit" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="kNr-Dp-1Dg" userLabel="Soft Egg Button">
<rect key="frame" x="0.0" y="0.0" width="111.5" height="247"/>
<rect key="frame" x="0.0" y="0.0" width="116" height="256.66666666666669"/>
<fontDescription key="fontDescription" type="system" weight="black" pointSize="18"/>
<state key="normal" title="Soft"/>
<connections>
<action selector="hardnessSelected:" destination="BYZ-38-t0r" eventType="touchUpInside" id="VKY-g0-G6y"/>
</connections>
</button>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="soft_egg" translatesAutoresizingMaskIntoConstraints="NO" id="88O-7T-MuC" userLabel="Soft Egg ImageView">
<rect key="frame" x="0.0" y="0.0" width="111.5" height="247"/>
</imageView>
</subviews>
<constraints>
<constraint firstAttribute="trailing" secondItem="88O-7T-MuC" secondAttribute="trailing" id="IRs-ev-NNF"/>
Expand All @@ -62,16 +67,19 @@
</constraints>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="WLA-so-IIR" userLabel="Medium Egg View">
<rect key="frame" x="131.5" y="0.0" width="111" height="247"/>
<rect key="frame" x="136" y="0.0" width="116" height="256.66666666666669"/>
<subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="medium_egg" translatesAutoresizingMaskIntoConstraints="NO" id="4F8-7w-xNb" userLabel="Medium Egg ImageView">
<rect key="frame" x="0.0" y="0.0" width="116" height="256.66666666666669"/>
</imageView>
<button opaque="NO" contentMode="scaleAspectFit" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Q3H-nl-7AG" userLabel="Medium Egg Button">
<rect key="frame" x="0.0" y="0.0" width="111" height="247"/>
<rect key="frame" x="0.0" y="0.0" width="116" height="256.66666666666669"/>
<fontDescription key="fontDescription" type="system" weight="black" pointSize="18"/>
<state key="normal" title="Medium"/>
<connections>
<action selector="hardnessSelected:" destination="BYZ-38-t0r" eventType="touchUpInside" id="h9o-ru-PXH"/>
</connections>
</button>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="medium_egg" translatesAutoresizingMaskIntoConstraints="NO" id="4F8-7w-xNb" userLabel="Medium Egg ImageView">
<rect key="frame" x="0.0" y="0.0" width="111" height="247"/>
</imageView>
</subviews>
<constraints>
<constraint firstItem="4F8-7w-xNb" firstAttribute="top" secondItem="WLA-so-IIR" secondAttribute="top" id="1ew-yl-YMM"/>
Expand All @@ -85,16 +93,19 @@
</constraints>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="SGU-B2-GCH" userLabel="Hard Egg View">
<rect key="frame" x="262.5" y="0.0" width="111.5" height="247"/>
<rect key="frame" x="272" y="0.0" width="116" height="256.66666666666669"/>
<subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="hard_egg" translatesAutoresizingMaskIntoConstraints="NO" id="60f-lw-4Iu" userLabel="Hard Egg ImageView">
<rect key="frame" x="0.0" y="0.0" width="116" height="256.66666666666669"/>
</imageView>
<button opaque="NO" contentMode="scaleAspectFit" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="NEu-V5-iHi" userLabel="Hard Egg Button">
<rect key="frame" x="0.0" y="0.0" width="111.5" height="247"/>
<rect key="frame" x="0.0" y="0.0" width="116" height="256.66666666666669"/>
<fontDescription key="fontDescription" type="system" weight="black" pointSize="18"/>
<state key="normal" title="Hard"/>
<connections>
<action selector="hardnessSelected:" destination="BYZ-38-t0r" eventType="touchUpInside" id="b2g-eD-d2g"/>
</connections>
</button>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="hard_egg" translatesAutoresizingMaskIntoConstraints="NO" id="60f-lw-4Iu" userLabel="Hard Egg ImageView">
<rect key="frame" x="0.0" y="0.0" width="111.5" height="247"/>
</imageView>
</subviews>
<constraints>
<constraint firstItem="NEu-V5-iHi" firstAttribute="leading" secondItem="SGU-B2-GCH" secondAttribute="leading" id="0lb-vV-Kxn"/>
Expand All @@ -110,29 +121,54 @@
</subviews>
</stackView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="nJN-th-c5K" userLabel="Timer View">
<rect key="frame" x="0.0" y="571.5" width="374" height="246.5"/>
<rect key="frame" x="0.0" y="591.33333333333337" width="388" height="256.66666666666663"/>
<subviews>
<progressView opaque="NO" contentMode="scaleToFill" verticalHuggingPriority="750" progressViewStyle="bar" progress="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="zoT-Ia-UOk">
<rect key="frame" x="0.0" y="126" width="388" height="6"/>
<constraints>
<constraint firstAttribute="height" constant="5" id="hhF-nc-bLL"/>
</constraints>
<color key="progressTintColor" systemColor="systemYellowColor"/>
<color key="trackTintColor" systemColor="systemGrayColor"/>
</progressView>
</subviews>
<constraints>
<constraint firstAttribute="trailing" secondItem="zoT-Ia-UOk" secondAttribute="trailing" id="ELm-1m-zqU"/>
<constraint firstItem="zoT-Ia-UOk" firstAttribute="centerY" secondItem="nJN-th-c5K" secondAttribute="centerY" id="fXb-EB-hyf"/>
<constraint firstItem="zoT-Ia-UOk" firstAttribute="leading" secondItem="nJN-th-c5K" secondAttribute="leading" id="oOq-Py-VkE"/>
</constraints>
</view>
</subviews>
</stackView>
</subviews>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
<color key="backgroundColor" red="0.79607843137254897" green="0.94901960784313721" blue="0.9882352941176471" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="wI6-ag-afn" firstAttribute="top" secondItem="8bC-Xf-vdC" secondAttribute="topMargin" id="8Bl-BK-cpF"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="bottom" secondItem="wI6-ag-afn" secondAttribute="bottom" id="TCD-uE-n4C"/>
<constraint firstItem="wI6-ag-afn" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leadingMargin" id="Wgn-J5-uGK"/>
<constraint firstAttribute="trailingMargin" secondItem="wI6-ag-afn" secondAttribute="trailing" id="dky-ZA-Z3J"/>
</constraints>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
<connections>
<outlet property="pageTitle" destination="XLm-5r-pSP" id="Kb4-SN-QHj"/>
<outlet property="progressBar" destination="zoT-Ia-UOk" id="KtV-CN-kOo"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="137.68115942028987" y="137.94642857142856"/>
</scene>
</scenes>
<resources>
<image name="hard_egg" width="287.5" height="366"/>
<image name="medium_egg" width="288" height="363"/>
<image name="soft_egg" width="287" height="365"/>
<image name="hard_egg" width="287.66665649414062" height="366.33334350585938"/>
<image name="medium_egg" width="288" height="363.33334350585938"/>
<image name="soft_egg" width="287" height="365.33334350585938"/>
<systemColor name="systemGrayColor">
<color red="0.55686274509803924" green="0.55686274509803924" blue="0.57647058823529407" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
<systemColor name="systemYellowColor">
<color red="1" green="0.80000000000000004" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
</resources>
</document>
38 changes: 38 additions & 0 deletions EggTimer/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,46 @@

import UIKit


class ViewController: UIViewController {
let eggTimes : [String : Int] = ["Soft": 3, "Medium": 4, "Hard": 7]
var remainingTime: Int = 60
var totalTime: Int = 0
var timer = Timer()

@IBOutlet weak var pageTitle: UILabel!
@IBOutlet weak var progressBar: UIProgressView!


@IBAction func hardnessSelected(_ sender: UIButton) {
timer.invalidate()
progressBar.progress = 0
let hardness = sender.currentTitle!
remainingTime = eggTimes[hardness]!
totalTime = eggTimes[hardness]!
pageTitle.text = hardness


timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(update), userInfo: nil, repeats: true)

}

@objc func update() {
if remainingTime > 0 {
print(remainingTime)
remainingTime -= 1

progressBar.progress = Float(totalTime - remainingTime) / Float(totalTime)
} else {
timer.invalidate()
pageTitle.text = "DONE!"
progressBar.progress = 1

}

}




}