How do I disable a UIButton?

后端 未结 6 1794
无人共我
无人共我 2020-12-03 00:22

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

相关标签:
6条回答
  • 2020-12-03 01:03

    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,

    0 讨论(0)
  • 2020-12-03 01:09

    Please set this...

     editButton.userInteractionEnabled = NO; 
    

    or You can use

     editButton.enabled = NO;
    
    0 讨论(0)
  • 2020-12-03 01:18
    yourBtn.userInteractionEnabled = NO; 
    
    0 讨论(0)
  • 2020-12-03 01:23

    Swift 3 and above

    editButton.isEnabled = false

    setEnabled is now part of the setter method for isEnabled.

    0 讨论(0)
  • 2020-12-03 01:25

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

     [editbutton setEnabled:NO];
    
    0 讨论(0)
  • 2020-12-03 01:25

    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

    0 讨论(0)
提交回复
热议问题