Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIButton UIControlEventTouchUpOutside Not Working

I have a custom UIButton. To create a custom background color when highlighted I the button (self) as an observer to three events:

[self addTarget:self action:@selector(didTapButtonForHighlight) forControlEvents:UIControlEventTouchDown];
[self addTarget:self action:@selector(didUnTapButtonForHighlight) forControlEvents:UIControlEventTouchUpInside];
[self addTarget:self action:@selector(didUnTapButtonForHighlight) forControlEvents:UIControlEventTouchUpOutside];

The first two work beautifully, and as long as I touch up inside the button the background gets set back to normal. However if I touch up outside the button the method didUnTapButtonForHighlight never gets called and the background remains the highlighted color. My code is a modified version of the code in Ondrej's answer to this question. Why is it not working? Thanks in advance.

like image 876
carloabelli Avatar asked Mar 22 '23 16:03

carloabelli


1 Answers

You should also test for UIControlEventTouchCancel in case you touch up way outside.

like image 157
Guelph Avatar answered Mar 25 '23 05:03

Guelph