Skip to content

Instantly share code, notes, and snippets.

@Tulakshana
Created November 13, 2017 12:55
Show Gist options
  • Save Tulakshana/fba4cef5d16c5d41f4c8a42cf4f919f3 to your computer and use it in GitHub Desktop.
Save Tulakshana/fba4cef5d16c5d41f4c8a42cf4f919f3 to your computer and use it in GitHub Desktop.
A custom UIButton which could have different background colours for enabled and disabled states.
class CustomButton: UIButton {
@IBInspectable private var enabledBackgroundColor: UIColor?
@IBInspectable private var disabledBackgroundColor: UIColor?
override var isEnabled: Bool {
set {
if newValue {
self.backgroundColor = enabledBackgroundColor
} else {
self.backgroundColor = disabledBackgroundColor
}
super.isEnabled = newValue
}
get {
return super.isEnabled
}
}
}
@chinghoi
Copy link

nice!

@Tulakshana
Copy link
Author

nice!

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment