IBDesignable from External Framework?

后端 未结 4 1298
悲&欢浪女
悲&欢浪女 2020-12-29 07:44

I\'d like to create some custom views that use the @IBDesignable and @IBInspectable tags. I have added these to my Framework and then linked my Fra

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-29 08:26

    I have a workaround. With this workaround, you don't need to add the framework as target. So it works with Carthage.

    @IBDesignable
    class MyCustomView: CustomView {
    
        @IBInspectable override var bgColor: NSColor {
            get {
                return super.bgColor
            }
            set {
                super.bgColor = newValue
            }
        }
    }
    

    Create a sub class (MyCustomView) of the custom class (CustomView) in the destination project (not in the framework project), and mark the sub class as @IBDesignable. Use sub class in your app. This way makes @IBDesignable work.

    Inside the sub class, override those @IBInspectable properties(bgColor), this way makes @IBInspectable work.

    You might encounter this issue: Loading code from a framework for a custom control in IBDesignable Following this guide to solve it: http://www.dribin.org/dave/blog/archives/2009/11/15/rpath/

    And please make both the custom class and its inspectable properties public otherwise this method doesn't compile.

    Please leave comments if you cannot get it work.

提交回复
热议问题