How to make editable values in storyboard using IBDesignable class?

479 Views Asked by At

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!

1

There are 1 best solutions below

0
Anton Barkov On BEST ANSWER

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
        }
    }
}