Created
March 1, 2016 16:04
-
-
Save kennylugo/f3f4619bfbb2b36df871 to your computer and use it in GitHub Desktop.
Tap Gesture : give random color to view on tap
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
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view, typically from a nib. | |
var tapGesture = UITapGestureRecognizer(target: self, action: "tap:") | |
self.view.addGestureRecognizer(tapGesture) | |
} | |
func tap(sender: AnyObject){ | |
let randomRed : CGFloat = CGFloat(drand48()) | |
let randomGreen : CGFloat = CGFloat(drand48()) | |
let randomBlue : CGFloat = CGFloat(drand48()) | |
self.view.backgroundColor = UIColor(red: randomRed, green: randomGreen, blue: randomBlue, alpha: 1) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment