Disable a Button Disable a Button swift swift

Disable a Button


The boolean value for NO in Swift is false.

button.isEnabled = false

should do it.

Here is the Swift documentation for UIControl's isEnabled property.


If you want the button to stay static without the "pressed" appearance:

// Swift 2editButton.userInteractionEnabled = false // Swift 3editButton.isUserInteractionEnabled = false 

Remember:

1) Your IBOutlet is --> @IBOutlet weak var editButton: UIButton!

2) Code above goes in viewWillAppear


The way I do this is as follows:

@IBAction func pressButton(sender: AnyObject) {    var disableMyButton = sender as? UIButton    disableMyButton.enabled = false}

The IBAction is connected to your button in the storyboard.

If you have your button setup as an Outlet:

    @IBOutlet weak var myButton: UIButton!

Then you can access the enabled properties by using the . notation on the button name:

    myButton.enabled = false