52

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?

vikingosegundo
  • 52,040
  • 14
  • 137
  • 178
Rahul
  • 951
  • 3
  • 10
  • 16

6 Answers6

111

Please set this...

 editButton.userInteractionEnabled = NO; 

or You can use

 editButton.enabled = NO;
Mehul Mistri
  • 15,037
  • 14
  • 70
  • 94
12

Swift 3 and above

editButton.isEnabled = false

setEnabled is now part of the setter method for isEnabled.

Community
  • 1
  • 1
Schemetrical
  • 5,506
  • 2
  • 26
  • 43
8

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

 [editbutton setEnabled:NO];
Jitendra
  • 5,055
  • 2
  • 22
  • 42
spjatkin
  • 91
  • 1
  • 2
7

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,

Jhaliya - Praveen Sharma
  • 31,697
  • 9
  • 72
  • 76
1

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

EvergreenTree
  • 1,788
  • 2
  • 16
  • 30
Patrick Domegan
  • 261
  • 2
  • 5
0
yourBtn.userInteractionEnabled = NO; 
Pradumna Patil
  • 2,180
  • 3
  • 17
  • 46