Created
January 22, 2017 06:01
-
-
Save staycreativedesign/983e9f2043cf5c837772d7d5f467287d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // ViewController.swift | |
| // fun facts | |
| // | |
| // Created by Gustavo Pares on 1/21/17. | |
| // Copyright © 2017 Gustavo Pares. All rights reserved. | |
| // | |
| import UIKit | |
| class ViewController: UIViewController { | |
| @IBOutlet weak var funFactLabel: UILabel! | |
| @IBOutlet weak var factBtn: UIButton! | |
| @IBOutlet weak var viewBG: UIView! | |
| let funFacts: [String] = ["this is awesome", "woot", "woot woot", "wooting is rough"] | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| funFactLabel.text = "An interesting fact" | |
| funFactLabel.textColor = UIColor.white | |
| factBtn.setTitleColor(.white, for: .normal) | |
| factBtn.setTitle("Click for an interesting fact", for: .normal) | |
| factBtn.backgroundColor = colorSelect(red: 100, green: 200, blue: 130) | |
| viewBG.backgroundColor = colorSelect(red: 204, green: 102, blue: 255) | |
| } | |
| override func didReceiveMemoryWarning() { | |
| super.didReceiveMemoryWarning() | |
| // Dispose of any resources that can be recreated. | |
| } | |
| @IBAction func factBtnClick(_ sender: UIButton) { | |
| sender.setTitle("More very interesting facts await..", for: .normal) | |
| funFactLabel.text = randomFact() | |
| viewBG.backgroundColor = randomColor() | |
| } | |
| func randomFact() -> String { | |
| let factPosition = arc4random_uniform(UInt32(funFacts.count)) | |
| let fact = funFacts[Int(factPosition)] | |
| return fact | |
| } | |
| func randomColor() -> UIColor { | |
| let green = arc4random_uniform(255) | |
| let red = arc4random_uniform(255) | |
| let blue = arc4random_uniform(255) | |
| return UIColor.init(colorLiteralRed: Float(red)/255, green: Float(green)/255, blue: Float(blue)/255, alpha: 1) | |
| } | |
| func colorSelect(red: Float, green: Float, blue: Float) -> UIColor { | |
| return UIColor.init(colorLiteralRed: red/255, green: green/255, blue: blue/255, alpha: 1) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment