How to blink a touch area in UILabel iPhone?

407 views Asked by At

I have an UILabel. I want to glow the touch area in it. That is, when I click on a point in that UILabel, a small circular portion around the touch point should be presented with glowing effect. How can get this?

3

There are 3 answers

0
Deepak Danduprolu On BEST ANSWER

Well you can do that by creating a CALayer or a CAGradientLayer based on how you want your glow and add it as a sublayer to the label's layer at the location of the touch.

For enabling the touch on UILabel, look at userInteractionEnabled property. You will need to set it to YES.

Then you will need to attach a UITapGestureRecognizer to the label for getting the tap. Once you have the touch location, add the custom glow layer as a subview to the label's layer in an invisible state. Animate the glow layer in and out. You might want to repeat a few times before removing the glow layer as a sublayer at completion.

0
morningstar On

Gesture recognizers are nice, but if you want to do something that starts when the finger touches, stops when the finger stops touching, and moves around with the finger in between, then it's hard to think of a good gesture recognizer for that. I think in that case you'd be better off just using touchesBegan, touchesMoved, and touchesEnded (don't forget touchesCancelled).

You can either put those methods on your view controller or subclass UILabel. Either way, set userInteractionEnabled = YES on the label.

As for how to graphically make that effect, I don't have any clever ideas for it at the moment.

1
Michael Dautermann On

UILabels don't respond to touches.

Use a UIButton with a custom type and provide images for the normal state and the (glowing) highlighted state.