Touch event detection on UILabel

I have a UILabel that I add programmatically to my main view. Then I add a gesture recognizer to receive touch events on the shortcut:

UITapGestureRecognizer *recog = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTouchNotification)]; [notification addGestureRecognizer:recog]; [recog release]; 

However, when you click the tag, nothing works. I checked all the subheadings to make sure the label was on top, and that is. The only way to get the recognizer to work is if I add it to the main view, but that doesn't help much. Does anyone know why this label behaves so "transparently"?

Happy Holidays!

+7
source share
1 answer

UILabel by default has the userInteractionEnabled property set to NO , so it does not receive touch events, and the gesture recognizer does not work. Try enabling user interaction with your label:

 ... notification.userInteractionEnabled = YES; ... 
+18
source

All Articles