Search code examples
iosswiftbuttondisable

How to disable a button if it is pressed in iOS?


I have been looking at the other tutorials on here to see how to make a button unable to be pressed. However, I keep getting this error:

'Value of type '(UIButton) -> ()' has no member 'isEnabled'

The code is:

@IBAction func PlayButton(_ sender: UIButton) {
    PlayButton.isEnabled = false
}

Solution

  • You do so by:

    sender.isEnabled = false
    

    Also note that your @IBAction function has the same name as the button. This causes a name ambiguity. Change the name of the function to something else.