I want to disable my UIButton, so I call:
button.enabled = FALSE;
However this makes the button see-through and I can see the elements underneath it. I don't mind that it changes colour, I just don't want it to be see-through.
I've tried ticking the boxes for 'opaque' and 'clip subviews' in IB, but no joy.
Is there an easy way to fix this? I suppose I could put a UIImageView with the same button image behind it, but it's hardly an elegant solution.
For a smooth and seamless experience, it's best to avoid graying out your disabled buttons. Instead, you should decrease the opacity to make it transparent. When the disabled button is transparent, users can see some semblance of the button in its enabled state.
Imagine a world in which every button is disabled by default. Usually it's grey, subtle and slightly out of focus, often with poor contrast and a subdued text label that's a bit difficult to decipher.
In this Swift code example, you will learn how to disable UIButton. The quickest way to disable the button in Swift is to simply set the button's isEnabled property to false. For example button. isEnabled = false.
A control that executes your custom code in response to user interactions.
You can also do:
button.adjustsImageWhenDisabled = NO;
Try userInteractionEnabled
property:
button.userInteractionEnabled = NO;
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