1

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!

sushi
  • 157
  • 1
  • 7

1 Answers1

1

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
        }
    }
}
EliteRaceElephant
  • 7,744
  • 4
  • 47
  • 62
Anton Barkov
  • 279
  • 2
  • 5