Reputation: 1298
I have a disabled button on top of enabled button:
The green button is disabled. When I click it, it triggers a click on the blue button behind.
I tried:
self.testButton.enabled = YES;
self.testButton.userInteractionEnabled = NO;
But I still got the same behavior
Is there any way to prevent the blue button click event in this scenario?
Edit:
Fixed by not really disabling the button but changing it's target to nil:
[myButton addTarget:nil action:nil forControlEvents:UIControlEventTouchUpInside];
[myButton setImage:[UIImage imageNamed:@"disabledImage.png"] forState:UIControlStateNormal];
Upvotes: 2
Views: 631
Reputation: 23053
Yes, blue button will always get an action as green button is not enable or intractable.
So, here you need one overlay between these two buttons to stop tap event of green button.
How ever below approach is not efficient way to tackle down this scenario, but you can use it unless you will find better one.
Add green button in a UIView
(Which work as an overlay between these two views) with same size as green button, add green button as a subview of this view and add this view at place of green button.
So that whenever you disable green button and tap on it. Tap will be on UIView
which is a superview of green button.
Use view hierarchy :
Upvotes: 3