I'd like to do an action if someone touches a predeclared UILabel
, something like:
if (label is touched) {
my actions;
}
Is there a method/way to do that?
I'd like to do an action if someone touches a predeclared UILabel
, something like:
if (label is touched) {
my actions;
}
Is there a method/way to do that?
You could use a gesture recognizer:
By default,
UILabel
isn't configured to accept touch input. However, if you use aUIButton
instead and set it to have a custom appearance, you can make it look like a (single-line) label and have it respond to touch events.You can subclass it and override the touch methods. You probably want to override
touchesEnded:withEvent:
.Or just use a UIButton.
You need to make sure userinteractionenabled is set to YES and then you can override the
touchesBegan:withEvent:
Just Add A category for UILabel Class and add your method to it.