Reputation: 4349
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.
Upvotes: 4
Views: 2824
Reputation: 308
You should also test for UIControlEventTouchCancel
in case you touch up way outside.
Upvotes: 6