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.
You should also test for UIControlEventTouchCancel
in case you touch up way outside.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With