diff --git a/EggTimer/Base.lproj/Main.storyboard b/EggTimer/Base.lproj/Main.storyboard index 2df29d93..1e29b4f4 100644 --- a/EggTimer/Base.lproj/Main.storyboard +++ b/EggTimer/Base.lproj/Main.storyboard @@ -1,9 +1,11 @@ - - + + - + + + @@ -12,17 +14,17 @@ - + - + - + - - + - + + + + - - - @@ -62,16 +67,19 @@ - + + + + - - - @@ -85,16 +93,19 @@ - + + + + - - - @@ -110,11 +121,27 @@ - + + + + + + + + + + + + + + + + + @@ -122,8 +149,11 @@ - + + + + @@ -131,8 +161,14 @@ - - - + + + + + + + + + diff --git a/EggTimer/ViewController.swift b/EggTimer/ViewController.swift index 0d9d8d79..d42b3c1a 100644 --- a/EggTimer/ViewController.swift +++ b/EggTimer/ViewController.swift @@ -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 + } + +} + + + }