I have managed to get the IBDesignable/IBInspectable
attributes working with direct subclasses of NSView
but not with a direct subclass of NSButton
. This is causing me to question if in fact the Cocoa implementation is somehow limited to NSView
only.
Almost every example on the web (and Apple WWDC 2014 Xcode video) use NSView
and then drag a custom view component from the library onto the canvas (and then change its class).
Is it possible to use IBDesignable
with subclasses of NSControl
and NSButton
etc...? I have seen many examples on the web using UIButton
.
If it is possible, then what are you supposed to drag from the library onto the canvas? It doesn't make sense for it to be a "custom view". On the other hand, there is no "custom control" available.
To be clear, I can get the IBInspectable attribute to show up at design time; but any changes don't seem to live render at design time.
The workaround is to wrap any custom NSButton
I want to create within an NSView
(via composition) but this seems like a bit of a hack...
I started playing around with a custom
NSButton
andNSButtonCell
.Dragging a button from the library onto the canvas and changing its class and the cell class doesn't live render. I think this is because Interface Builder still does a lot of custom things to setup
NSButtonCell
.What works fine for me is dragging a custom view from the library onto the canvas and set its class. For this to work you need to setup the cell inside NSButtons
-initWithCoder:
.Also I found a sample from Apple with a layer-backed custom Checkbox.