Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Blakeasd

macrumors 6502a
Original poster
Dec 29, 2009
643
0
Hello!
Does anyone know of a good tutorial on making custom buttons by subclassing them? I have looked all over and have not found one that has been helpful. Please do not link me to any Apple Documentation.
Thanks,
-Blake
 
Hello!
Does anyone know of a good tutorial on making custom buttons by subclassing them? I have looked all over and have not found one that has been helpful. Please do not link me to any Apple Documentation.
Thanks,
-Blake

It would be helpful to know what you are trying to do with it, and why you cannot use delegates to get what you need. In Cocoa/Obj-C you don't really subclass things all that often, esp. when compared to languages like Java.
 
I want to try to make iPhone type buttons(Just how they look). I know that doesn't follow human-interface guidelines, but I need it for something I am doing. Anyway please respond and thanks :)
-Blake
 
I want to try to make iPhone type buttons(Just how they look). I know that doesn't follow human-interface guidelines, but I need it for something I am doing. Anyway please respond and thanks :)
-Blake

https://sites.google.com/site/randomprogrammingsamples/iPhoneBtn.tgz?attredirects=0&d=1

This should get you started, you will obviously want a better image(probl with transparency as well), I just took a quick screenshot of a button from the iPhone simulator.

The basics is that you have to subclass NSButtonCell and override a few of NSCells methods(namely the initialization and drawing methods). You also have to make sure to keep everything sized appropriately, this code does that.

You also have to make sure you change the class of the button's CELL in IB, you can also just copy/paste the button once you have one setup.

Hope this helps.
 
^ missing image ;)

iphonebtn_missing.png
 
This is a stupid question, but how exactly to I drag a NSButtonCell to my window. It just drags back to the library?
 
This is a stupid question, but how exactly to I drag a NSButtonCell to my window. It just drags back to the library?

Switch your nib window (the window that shows the nib contents) to list view. From there you can expand items until you see your button. Select the cell (which you get to by expanding the button) and set the cell's class in the info pane of the inspector panel.
 
You can also create a custom button appearance without subclassing. Just create the on and off images, then create your button in Interface Builder as a Square Button. Add the images to your project, and set them as the Image and Alt. Image on the button. Set the Border to off, and change the Type to Momentary Change.

Reasons to subclass would be: nice appearance no matter the size of the button (can also be done with vector graphics too, e.g. PDF), mouse-over effects, and custom text styling.

Which of the iPhone buttons are you trying to reproduce? Can you provide a screenshot?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.