Skip to content

Instantly share code, notes, and snippets.

@staycreativedesign
Created January 23, 2017 19:28
Show Gist options
  • Select an option

  • Save staycreativedesign/7ee91aa7e44a4f95fc0cfabe4a9a8a72 to your computer and use it in GitHub Desktop.

Select an option

Save staycreativedesign/7ee91aa7e44a4f95fc0cfabe4a9a8a72 to your computer and use it in GitHub Desktop.
First app
//
// FactProvider.swift
// fun facts
//
//
import Foundation
struct FactProvider {
let facts: [String] = ["this is awesome", "woot", "woot woot", "wooting is rough"]
func randomFact() -> String {
let factPosition = arc4random_uniform(UInt32(facts.count))
return facts[Int(factPosition)]
}
}
//
// RandomColorGenerator.swift
// fun facts
//
//
import UIKit
func randomColor() -> UIColor {
let red = randomNumber()
let green = randomNumber()
let blue = randomNumber()
let color = UIColor(colorLiteralRed: red/255, green: green/255, blue: blue/255, alpha: 1)
return color
}
func randomNumber() -> Float {
let number = Float(arc4random_uniform(255))
return number
}
//
// ViewController.swift
// fun facts
//
//
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var factLbl: UILabel! {
didSet {
factLbl.textColor = UIColor.white
}
}
@IBOutlet weak var factBtn: UIButton! {
didSet {
factBtn.setTitle("Hello", for: .normal)
factBtn.setTitleColor(.white, for: .normal)
}
}
let fact = FactProvider()
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = randomColor()
factLbl.text = "Some interesting facts"
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func factBtn(_ sender: UIButton) {
factLbl.text = fact.randomFact()
view.backgroundColor = randomColor()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment