I have Multiple Buttons on my UI, and I want to execute different functions according to different types of click,
- Single Click
- Double Click
- Long Press
Doing it for single tap was easy for me, an IBAction with all the four buttons connected to it, but for the other types of clicks i was stuck,
I understand that i need to use the tap gesture recognizer, but I'm unable to set it to multiple UIButtons,
Here is and example of what I want to do
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var Label: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func ButtonSingleTap(sender:UIButton!) {
let ButtonNumber: String = String(sender.tag)
Label.text = "Button " + ButtonNumber + " is Single Tapped"
}
func ButtonDoubleTap(sender:UIButton!) {
let ButtonNumber: String = String(sender.tag)
Label.text = "Button " + ButtonNumber + " is Double Tapped"
}
func ButtonLongTap(sender:UIButton!) {
let ButtonNumber: String = String(sender.tag)
Label.text = "Button " + ButtonNumber + " is Long Pressed"
}
}