我在用户定义的运行时属性中为UIbutton设置了CornerRadius和BorderWidth.在不增加layer.borderColor的情况下,它可以很好地工作,并以黑色显示边框.但是当add layer.borderColor不起作用时(不显示边框).
我在用户定义的运行时属性中为UIbutton设置了CornerRadius和BorderWidth.在不增加layer.borderColor的情况下,它可以很好地工作,并以黑色显示边框.但是当add layer.borderColor不起作用时(不显示边框).
For Swift:
Swift 3:个
extension UIView {
@IBInspectable var cornerRadius: CGFloat {
get {
return layer.cornerRadius
}
set {
layer.cornerRadius = newValue
layer.masksToBounds = newValue > 0
}
}
@IBInspectable var borderWidth: CGFloat {
get {
return layer.borderWidth
}
set {
layer.borderWidth = newValue
}
}
@IBInspectable var borderColor: UIColor? {
get {
return UIColor(cgColor: layer.borderColor!)
}
set {
layer.borderColor = newValue?.cgColor
}
}
}
Swift 2.2:个
extension UIView {
@IBInspectable var cornerRadius: CGFloat {
get {
return layer.cornerRadius
}
set {
layer.cornerRadius = newValue
layer.masksToBounds = newValue > 0
}
}
@IBInspectable var borderWidth: CGFloat {
get {
return layer.borderWidth
}
set {
layer.borderWidth = newValue
}
}
@IBInspectable var borderColor: UIColor? {
get {
return UIColor(CGColor: layer.borderColor!)
}
set {
layer.borderColor = newValue?.CGColor
}
}
}