我正在使用@IBInspectable
来设置一个Swift扩展中的UIButton
边框颜色,代码如下:
extension UIButton {
@IBInspectable var borderWidth: CGFloat {
get {
return layer.borderWidth
}
set {
layer.borderWidth = newValue
layer.masksToBounds = newValue > 0
}
}
}
...但我还想为按钮的.Selected
状态添加一个selectedBorderColor
属性。使用这样的扩展是否可行?或者我必须子类化UIButton
并以某种方式检查按钮状态呢?
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
}
}
}
感谢您的提前帮助。