I have a UILabel that I am adding programmatically to my main view. I then add a gesture recognizer to get touch events on the label:
UITapGestureRecognizer *recog = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTouchNotification)];
[notification addGestureRecognizer:recog];
[recog release];
However, nothing fires when the label is touched. I logged all subviews to make sure the label was on top, and it is. The only way I can get the recognizer to work is if I add it to the underlying view, but that isn't much help. Does anyone know why this label is behaving so "transparently"?
Happy holidays!
UILabel
has its userInteractionEnabled
property set to NO
by default so it does not receive touch events and gesture recognizer does not work. Try to enable user interaction for your label:
...
notification.userInteractionEnabled = YES;
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With