如何禁用UIButton?

时间:2022-07-11 19:44:13

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.

我正在做一个项目,在这个项目中,我必须在plist中显示照片库的所有照片,并在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.

我的应用程序也会有一个编辑按钮:当用户点击这个按钮时,每个按钮上都会显示一个删除标记(比如通常出现在其他iPhone/iPad应用程序中)。

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?

…但它既不会产生错误,也不会起作用。我应该做什么?

5 个解决方案

#1


94  

Please set this...

请设置这个…

 editButton.userInteractionEnabled = NO; 

or You can use

或者您也可以使用

 editButton.enabled = NO;

#2


7  

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

使用UIControl的enabled属性,UIControl是UIButton的超类,将它设置为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,

您也可以尝试@Marvin建议的,在这种情况下,您的按钮不会响应用户的任何触摸事件,

#3


5  

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

属性启用的setter在类UIButton中被重写。试着发个信息。

 [editbutton setEnabled:NO];

#4


1  

In addition to the above:

除上述外:

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

设置editButton。userInteractionEnabled =没有;也可以使用editButton。启用=没有;

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

您可能想要将按钮变灰,以便用户知道它已被禁用:editButton。α= 0.66

#5


0  

yourBtn.userInteractionEnabled = NO; 

#1


94  

Please set this...

请设置这个…

 editButton.userInteractionEnabled = NO; 

or You can use

或者您也可以使用

 editButton.enabled = NO;

#2


7  

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

使用UIControl的enabled属性,UIControl是UIButton的超类,将它设置为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,

您也可以尝试@Marvin建议的,在这种情况下,您的按钮不会响应用户的任何触摸事件,

#3


5  

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

属性启用的setter在类UIButton中被重写。试着发个信息。

 [editbutton setEnabled:NO];

#4


1  

In addition to the above:

除上述外:

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

设置editButton。userInteractionEnabled =没有;也可以使用editButton。启用=没有;

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

您可能想要将按钮变灰,以便用户知道它已被禁用:editButton。α= 0.66

#5


0  

yourBtn.userInteractionEnabled = NO;