PatrickGamboa
PatrickGamboa

Reputation: 672

Create custom buttons for Interface Builder

Does anyone know how to create custom buttons for Interface Builder? Like instead of have just a regular Round Rect Button, I want to have like a custom 3D button and some random image background for that button. How to do this?

Upvotes: 5

Views: 7590

Answers (3)

nylund
nylund

Reputation: 1105

It's probably easiest to use an image as the background for the button. For example you can use this tool to easily generate buttons with gradients, http://itunes.apple.com/us/app/uibutton-builder/id408204223?mt=8

If you want anything more fancy it's probably time to start Photoshop ;-)

Upvotes: 0

Joshua Nozzi
Joshua Nozzi

Reputation: 61238

You will either need to find a third-party class (ideally with an Interface Builder plug-in so you can see it live in the IB file) or subclass UIButton or NSButton/NSButtonCell for Mac and provide your own 3D rainbow unicorn drawing behavior. :-)

Interface Builder can only show you classes it knows about - you can't add behavior / modify existing drawing behavior there because that's the wrong tool for the job. You'll need to find someone else's or subclass your own in code then let IB know about it.

Update based on OP's comment

You can use -setImage:forState: to supply your custom image for the given states.

Upvotes: 2

Dominic
Dominic

Reputation: 3304

To do it in Interface Builder is prohibitively complicated (writing an Interface Builder plugin is a non-trivial task). However, you can subclass UIControl (which is just a UIView) and define your custom drawing in the subclass.

Then, in Interface Builder, change the class of the object you've subclassesed to your new class, and everything should work correctly.

Relevant reading:

Upvotes: 1

Related Questions