Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIButton Press and Hold

Tags:

ios

uibutton

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.

like image 441
user1120008 Avatar asked Nov 27 '22 22:11

user1120008


1 Answers

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];
like image 164
sudo rm -rf Avatar answered Dec 09 '22 16:12

sudo rm -rf