Search code examples
iosobjective-cxcodeibdesignableibinspectable

IBInspectable and protocols


I'm using new Xcode 6 feature called "LiveRendering". As i need to use some inspectable properties a lot on different custom views, i want to declare them in protocols.

For example :

  • LiveRenderingTextAttributesProtocol (that declares inspectable properties for textColor, textSize
  • LiveRenderingBorderAttributesProtocol (that declares inspectable properties for borderStyle, borderColor, borderWidth)

etc ...

After that, each custom view implements the protocols it needs.

But i can't see my inspectable properties on InterfaceBuilder "Attributes inspector" column :/ The LiveRendering is working well when I define the values for these properties as "Used Defined Runtime Attributes", but i want to see them in my Attributes inspector column.

An idea to solve this problem please ?


Solution

  • A protocol defines a set of optional or required methods and attributes to be compliant with, but it's the class the responsible for implementing them. To be able to have reusable base IBInspectable properties you could have a superclass like MyInspectableView that has those properties declared and implemented, so you can subclass it and have those IBInspectables shared between all of them.