如何使用 IBDesignable class 在故事板中制作可编辑的值?

How to make editable values in storyboard using IBDesignable class?

我想知道如何为 UITextView 创建可重用的@IBDesignable class,我可以直接从 Storyboard 更改边框宽度、颜色等?

提前致谢!

你re-route视图层的值,像这样:

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