Skip to content

Instantly share code, notes, and snippets.

@kennylugo
Created March 1, 2016 16:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kennylugo/f3f4619bfbb2b36df871 to your computer and use it in GitHub Desktop.
Save kennylugo/f3f4619bfbb2b36df871 to your computer and use it in GitHub Desktop.
Tap Gesture : give random color to view on tap
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