Skip to content
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
46 changes: 41 additions & 5 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">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="19455" 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"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14766.15"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19454"/>
<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 @@ -21,9 +23,9 @@
<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"/>
<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">
<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="374" height="246.5"/>
<fontDescription key="fontDescription" type="system" pointSize="30"/>
<fontDescription key="fontDescription" type="system" pointSize="47"/>
<color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
Expand All @@ -45,6 +47,9 @@
<rect key="frame" x="0.0" y="0.0" width="111.5" height="247"/>
<fontDescription key="fontDescription" type="system" weight="black" pointSize="18"/>
<state key="normal" title="Soft"/>
<connections>
<action selector="hardEgg:" destination="BYZ-38-t0r" eventType="touchUpInside" id="XvN-Kn-JN5"/>
</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"/>
Expand All @@ -68,6 +73,9 @@
<rect key="frame" x="0.0" y="0.0" width="111" height="247"/>
<fontDescription key="fontDescription" type="system" weight="black" pointSize="18"/>
<state key="normal" title="Medium"/>
<connections>
<action selector="hardEgg:" destination="BYZ-38-t0r" eventType="touchUpInside" id="9bG-Go-GGD"/>
</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"/>
Expand All @@ -91,6 +99,9 @@
<rect key="frame" x="0.0" y="0.0" width="111.5" height="247"/>
<fontDescription key="fontDescription" type="system" weight="black" pointSize="18"/>
<state key="normal" title="Hard"/>
<connections>
<action selector="hardEgg:" destination="BYZ-38-t0r" eventType="touchUpInside" id="Gx6-kG-qy0"/>
</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"/>
Expand All @@ -111,19 +122,38 @@
</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"/>
<subviews>
<progressView opaque="NO" contentMode="scaleToFill" verticalHuggingPriority="750" progressViewStyle="bar" translatesAutoresizingMaskIntoConstraints="NO" id="UdY-SF-a9c">
<rect key="frame" x="0.0" y="118" width="374" height="11"/>
<constraints>
<constraint firstAttribute="height" constant="10" id="BXA-uq-eEQ"/>
</constraints>
<color key="progressTintColor" systemColor="systemYellowColor"/>
<color key="trackTintColor" systemColor="systemGrayColor"/>
</progressView>
</subviews>
<constraints>
<constraint firstItem="UdY-SF-a9c" firstAttribute="centerY" secondItem="nJN-th-c5K" secondAttribute="centerY" id="2lA-8d-lNR"/>
<constraint firstAttribute="trailing" secondItem="UdY-SF-a9c" secondAttribute="trailing" id="3uJ-MF-iQp"/>
<constraint firstItem="UdY-SF-a9c" firstAttribute="leading" secondItem="nJN-th-c5K" secondAttribute="leading" id="bA2-cc-2vB"/>
</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="progressBar" destination="UdY-SF-a9c" id="I5i-I9-u0O"/>
<outlet property="textLabel" destination="XLm-5r-pSP" id="5kf-i1-LHq"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
Expand All @@ -134,5 +164,11 @@
<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"/>
<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>
61 changes: 59 additions & 2 deletions EggTimer/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,66 @@
//

import UIKit
import AVFoundation

class ViewController: UIViewController {
@IBOutlet weak var textLabel: UILabel!

@IBOutlet weak var progressBar: UIProgressView!



let eggTime = ["Soft": 10, "Medium": 420, "Hard": 720]
var totalTime = 0;
var secondsPassed = 0
let timer = Timer()
var player = AVAudioPlayer()

@IBAction func hardEgg(_ sender: UIButton) {

let hardness = sender.currentTitle

totalTime = eggTime[hardness!]!

Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(updateTimer), userInfo: nil, repeats: true)


switch hardness {
case "Soft":
print(eggTime[hardness!]!)


case "Medium":
print(eggTime[hardness!]!)

case "Hard":
print(eggTime[hardness!]!)

default:
print("Error")
}
}

@objc func updateTimer(){
if secondsPassed < totalTime {

let percentageProgress = Float(secondsPassed) / Float(totalTime)
print("\(percentageProgress)")
progressBar.progress = percentageProgress

secondsPassed += 1
} else {
timer.invalidate()
textLabel.text = "DONE BC!"
let path = Bundle.main.path(forResource: "alarm_sound", ofType : "mp3")!
let url = URL(fileURLWithPath : path)
do {
player = try AVAudioPlayer(contentsOf: url)
player.play()
} catch {
print ("There is an issue with this code!")
}
}
}



}