Ios – UIButton Press and Hold

iosuibutton

I'd like to implement a press and hold button. So when you push the button, function A executes, and when you release, function B executes. I found this, but it wasn't what I was quite looking for.

UIButton Touch and Hold

I don't want any repeating action.

Best Answer

Just add different selectors to the UIButton based on different events. To set the selector for when you initially press down, do the following

[button addTarget:self action:@selector(buttonDown:) forControlEvents:UIControlEventTouchDown];

and the selector for when your button is released:

[button addTarget:self action:@selector(buttonUp:) forControlEvents:UIControlEventTouchUpInside];