Search code examples
iosswiftuibuttonswift2uicontrol

Override UIButton's setEnabled method in Swift


In Swift, UIControl doesn't seem to have a setEnabled: method. Is there a way to detect when the control state was changed?


Solution

  • You can do something like that in your subclass:

    override var enabled:Bool {
        didSet {
            //Your code
        }
    }
    

    Swift 3.0

    override var isEnabled:Bool {
        didSet {
            //Your code
        }
    }