daspianist
daspianist

Reputation: 5495

Disable UIButton from interaction without changing UIButton look (i.e. greyed out look)

I have the following code where my goal is to disable a UIButton from interaction once it is in the selected mode.

if (...){
    cell.requestButton.selected = YES;
    cell.requestButton.enabled = NO;
} else {
    cell.requestButton.selected = NO;
    cell.requestButton.enabled = YES;
}

The side-effect of disabling the UIButton is that it also changes the Button's appearance. Even if I set the same UIImage for both the button's both selected and disabled state, the appearance still takes on a greyed-out looked with a <1 alpha level. Is there a way that I could prevent the disabled state from changing the appearance of the UIButton at all?

Thanks!

Upvotes: 1

Views: 526

Answers (2)

Rich
Rich

Reputation: 8202

Either set the same style as the UIControlStateNormal to the UIControlStateDisabled or have a look at adjustsImageWhenDisabled.

Upvotes: 1

Thomas Tempelmann
Thomas Tempelmann

Reputation: 12053

Try setting the UIView's userInteractionEnabled property instead. Not sure if that works, but give it a try. If that doesn't work, you could place a dummy UIView right over it, add constraints to use the original button's position and size, and have it enabled so that it swallows any taps.

Upvotes: 3

Related Questions