I want to hide the border of a button when it's disabled. When it's enabled, I set the border like this:
_btnInit.layer.borderWidth = 1;
_btnInit.layer.borderColor = [[UIColor grayColor]CGColor];
And when it's disabled, I want to delete the border.

Like in the picture. The left is in the disabled state and the right is at the normal state.
Subclass UIButton and override isEnabled property like this,
override var isEnabled: Bool {
didSet {
if isEnabled {
self.layer.borderColor = UIColor.black.cgColor
self.layer.borderWidth = 1.0
} else {
self.layer.borderWidth = 0.0
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With