For those who have Googled “disabled the button,” but may have more subtle use cases:
Disable with visual effect: as others have already said, this will prevent the button from being pressed, and the system will automatically make it disabled:
yourButton.isEnabled = false
Disable without visual effect. Do you use the button if it should look normal, but does not respond to touch? Try this!
yourButton.userInteractionEnabled = false
Hide without disconnecting: this approach hides the button without disconnecting it (invisibly, but you can still click):
yourButton.alpha = 0.0
Delete: This will completely remove the view:
yourButton.removeFromSuperView()
Press something after the button: the two buttons are folded and you want the top button to temporarily work as if it weren’t there? If you no longer need the top button, remove it. If you need it again, try reducing its height or width to 0!
Dave G May 26 '19 at 13:37 2019-05-26 13:37
source share