Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // 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)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement