I have a label with UITapGestureRecognizer and longgestureRecognizer:
let gestureRecognizer = UITapGestureRecognizer(target: self, action: Selector("labelPressed:"))
let longgestureRecognizer = UILongPressGestureRecognizer(target: self, action: Selector("longLabelPressed:"))
label.addGestureRecognizer(gestureRecognizer)
label.addGestureRecognizer(longgestureRecognizer)
I want to change the color, as in UIButton, when he clicked:
func longLabelPressed(recognizer:UILongPressGestureRecognizer){
if let label = recognizer.view as? UILabel {
if recognizer.state == .Began {
label.textColor = UIColor.redColor()
}
if recognizer.state == .Ended {
label.textColor = UIColor.blackColor()
}
}
}
But how to determine the event of the end of the event?
func labelPressed(recognizer:UITapGestureRecognizer) {
if let label = recognizer.view as? UILabel {
}
}
My goal is to create a shortcut like UIButton with touch events.
source
share