I'm wondering how to create reusable @IBDesignable class for UITextView with which I could change border width, colour, etc. directly from the Storyboard?
Thanks in advance!
You re-route the value to the view's layer, like so:
@IBDesignable class TextView: UITextView {
@IBInspectable var borderColor: UIColor? {
set {
layer.borderColor = newValue?.cgColor
}
get {
guard let borderColor = layer.borderColor else {
return nil
}
return UIColor(cgColor: borderColor)
}
}
@IBInspectable var borderWidth: CGFloat {
set {
layer.borderWidth = newValue
}
get {
return layer.borderWidth
}
}
}