I am using @IBInspectable to set a border color on a UIButton using a Swift extension like this:
extension UIButton {
@IBInspectable var borderWidth: CGFloat {
get {
return layer.borderWidth
}
set {
layer.borderWidth = newValue
layer.masksToBounds = newValue > 0
}
}
}
...but I also want to have a selectedBorderColor property for the .Selected state of the button. Is this possible with an extension like this? Do I have to subclass UIButton and check the button state somehow instead?
extension UIButton {
@IBInspectable var borderWidth: CGFloat {
get {
return layer.borderWidth
}
set {
layer.borderWidth = newValue
layer.masksToBounds = newValue > 0
}
}
//This is what I want to do...
@IBInspectable var selectedBorderWidth: CGFloat {
get {
return layer.borderWidth
}
set {
layer.borderWidth = newValue
layer.masksToBounds = newValue > 0
}
}
}
Thanks in advance.
You can subclass
UIButtonlike this:and use
button.selected = true