How do I disable a UIButton?

IosObjective CCocoa TouchUibutton

Ios Problem Overview


I am working on a project in which I have to show all photos of Photo Library in a plist and show them horizontally on UIButtons.

My app will also have an edit button: when the user clicks this button, a delete mark (such as usually appears in other iPhone/iPad apps) should show on each button.

But here's the crucial bit: as soon as this delete mark appears, the functionality of the button should be disabled. I've tried accomplishing this with the following:

{
  editbutton.enabled=NO;
}

...but it neither produces an error nor works. What should I do?

Ios Solutions


Solution 1 - Ios

Please set this...

 editButton.userInteractionEnabled = NO; 

or You can use

 editButton.enabled = NO;

Solution 2 - Ios

Swift 3 and above

editButton.isEnabled = false

setEnabled is now part of the setter method for isEnabled.

Solution 3 - Ios

setter for property enabled is overridden in class UIButton. try to send a message.

 [editbutton setEnabled:NO];

Solution 4 - Ios

Use the enabled property of UIControl which the super class of UIButton and set it with NO.

myButton.enabled = NO;

You could also try as @Marvin suggested, In that case your button will not respond to any touch event from user,

Solution 5 - Ios

In addition to the above:

Set editButton.userInteractionEnabled = NO; or you can use editButton.enabled = NO;

You might want to gray out the button so the user knows it was disabled: editButton.alpha = 0.66

Solution 6 - Ios

yourBtn.userInteractionEnabled = NO; 

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRahulView Question on Stackoverflow
Solution 1 - IosMehul MistriView Answer on Stackoverflow
Solution 2 - IosSchemetricalView Answer on Stackoverflow
Solution 3 - IosspjatkinView Answer on Stackoverflow
Solution 4 - IosJhaliya - Praveen SharmaView Answer on Stackoverflow
Solution 5 - IosPatrick DomeganView Answer on Stackoverflow
Solution 6 - IosPradumna PatilView Answer on Stackoverflow