a
How can I customize UIButton/NSButton?

How can I customize UIButton/NSButton?

UIButton

You can use the setBackgroundImage:forState: (Swift: setBackgroundImage(_:forState:)) method.

Another approach is to use a delegate of a custom CALayer that implements drawInContext: method (from where you call your StyleKit drawing code) and use this custom CALayer as a sublayer of your button’s layer.

It is not recommended to subclass UIButton to customize its style.

NSButton

You can subclass NSButton or NSButonCell and override some of these methods: drawBezelWithFrame:inView:, drawImageWithFrame:inView:,drawTitle:withFrame:inView:drawRect:. Call StyleKit drawing methods in these overriden methods. Another approach is to use a delegate of a custom CALayer that implements drawInContext: method (from where you call your StyleKit drawing code) and use this custom CALayer as a sublayer of your button’s layer.

Please, check out the "Example.pcvd" document, particularly the "Button" canvas in "TabBar and Button" tab in example project to see how to customize UIButton.

For implementation, take a look at the EXTabBarsAndButtonsViewController subclass.