Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. //
  2. // ViewController.swift
  3. // fun facts
  4. //
  5. // Created by Gustavo Pares on 1/21/17.
  6. // Copyright © 2017 Gustavo Pares. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10.  
  11. class ViewController: UIViewController {
  12.  
  13. @IBOutlet weak var funFactLabel: UILabel!
  14. @IBOutlet weak var factBtn: UIButton!
  15. @IBOutlet weak var viewBG: UIView!
  16.  
  17. let funFacts: [String] = ["this is awesome", "woot", "woot woot", "wooting is rough"]
  18.  
  19.  
  20. override func viewDidLoad() {
  21. super.viewDidLoad()
  22. funFactLabel.text = "An interesting fact"
  23. funFactLabel.textColor = UIColor.white
  24. factBtn.setTitleColor(.white, for: .normal)
  25. factBtn.setTitle("Click for an interesting fact", for: .normal)
  26. factBtn.backgroundColor = colorSelect(red: 100, green: 200, blue: 130)
  27. viewBG.backgroundColor = colorSelect(red: 204, green: 102, blue: 255)
  28. }
  29.  
  30. override func didReceiveMemoryWarning() {
  31. super.didReceiveMemoryWarning()
  32. // Dispose of any resources that can be recreated.
  33. }
  34.  
  35.  
  36. @IBAction func factBtnClick(_ sender: UIButton) {
  37. sender.setTitle("More very interesting facts await..", for: .normal)
  38. funFactLabel.text = randomFact()
  39. viewBG.backgroundColor = randomColor()
  40.  
  41. }
  42.  
  43. func randomFact() -> String {
  44. let factPosition = arc4random_uniform(UInt32(funFacts.count))
  45. let fact = funFacts[Int(factPosition)]
  46. return fact
  47. }
  48.  
  49. func randomColor() -> UIColor {
  50. let green = arc4random_uniform(255)
  51. let red = arc4random_uniform(255)
  52. let blue = arc4random_uniform(255)
  53. return UIColor.init(colorLiteralRed: Float(red)/255, green: Float(green)/255, blue: Float(blue)/255, alpha: 1)
  54. }
  55.  
  56. func colorSelect(red: Float, green: Float, blue: Float) -> UIColor {
  57. return UIColor.init(colorLiteralRed: red/255, green: green/255, blue: blue/255, alpha: 1)
  58. }
  59.  
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement