How to find out the amount of time a button is being touched in iphone?
My requirement is to change a button color based on the time it is being pressed. for ex,button should be in re开发者_如何学God color if it is being touched for one sec, green for two secs, etc. How do i do it?
I could find out the amount of time after user takes his hand out, but I want it to be done when it is being pressed?. What is the efficient way to do it?.
U can start an NSTimer which fires every second , which is started when UIButton UIControlEventTouchDown
control event is generated. And stop the timer when UIControlEventTouchUpInside
or UIControlEventTouchUpOutside
or UIControlEventTouchCancel
event is generated. In between u can do the changes.
精彩评论