【问题标题】:How to make editable values in storyboard using IBDesignable class?如何使用 IBDesignable 类在情节提要中制作可编辑的值?
【发布时间】:2021-02-17 11:10:08
【问题描述】:

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

提前致谢!

【问题讨论】:

    标签: swift uitextview xcode12 ibdesignable


    【解决方案1】:

    您将值重新路由到视图的层,如下所示:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-12-08
      • 2019-09-29
      • 1970-01-01
      • 2015-01-02
      • 2017-10-04
      • 2017-12-20
      • 2012-02-24
      相关资源
      最近更新 更多