I am trying to set the custom border color of UIView programmatically in Swift.
Use @IBDesignable and @IBInspectable to do the same.
They are re-useable, easily modifiable from the Interface Builder and the changes are reflected immediately in the Storyboard
Conform the objects in the storyboard to the particular class
Code Snippet:
@IBDesignable
class CustomView: UIView{
@IBInspectable var borderWidth: CGFloat = 0.0{
didSet{
self.layer.borderWidth = borderWidth
}
}
@IBInspectable var borderColor: UIColor = UIColor.clear {
didSet {
self.layer.borderColor = borderColor.cgColor
}
}
override func prepareForInterfaceBuilder() {
super.prepareForInterfaceBuilder()
}
}
Allows easy modification from Interface Builder: