Need someone who is fluent in subclassing

Ok, so instead of dealing with annoying images I decided to try and create true custom controls. Right now all I need is a square button. I have the 6 graphics ready for the pressed and unpressed state. I just need some help putting it all together. I believe I will need to make a button.m and button.h along with a buttoncell.m and buttoncell.h

I know it would be really tedious to type out all the obj-c code but any help is appreciated:)

  • Hendo

Controls that do what? How could we possibly create something custom without having any idea what is different about your class than is possible with the basic NSButton class? Are you just toggling between two different states (i.e. a “toggle” button)? Please elaborate on what you’re trying to do… EXACTLY… that you can’t do with what the nsbutton class already provides.

It’s a continuation of this thread: http://bbs.applescript.net/viewtopic.php?id=22155

Yeah, I figured I’d create a new topic though, because it more now focuses on obj-c and custom controls. Sorry for that lack of info I gave, that was my bad.

Basically jobu you read my mind. I need a toggle button that supports icons/alternate icons (i think toggle buttons already do.) The reason is because my new app is done in a HUD style window and i couldn’t find good buttons for play pause, fast forwarding and rewinding. Obviously a regular NSButton would not look good on a HUD style app. (If you don’t know what HUD style is look at this screenshot:)
http://i113.photobucket.com/albums/n236/hendo13/newscreen.png

The play, fast forward and rewind buttons are just images with a transparent square button overtop of them. For the fast forward and rewind buttons it works fine anyway, but the play button has to switch icons or in my case it has to switch the whole image, and thats really slow and inefficient. But yes truly just a custom square shaped toggle button that can handle icons/alternate icons is all I need. Like I said I already have the images ready so that’s all good. Thanks!

  • Hendo

From what I understand, there’s no reason you can’t use a regular button (configured properly, of course) using the settings available to you in IB. First, add a button to your window. Make it a square button, set it’s ‘Behavior’ setting to “Toggle”, set the ‘Icon Pos’ to just a centered icon, and uncheck the “Bordered” checkbox. Tracking of the on/off state is handled for you. You can also set the state manually using “set state to…”, perhaps in response to external change of state such as the track ending or itunes changing state outside of your controller. Next, make your images. I made two png images in my test projest with a play and pause icon, made them 50% transparent, and added them as the icon and alternate icon of my button. With a semi-transparent window and buttons, I could easily achieve the same look as the screenie you posted using only regular buttons (not subclassed) and the custom subclass you’re already using for your window.

hey, thats an interesting way of doing it…I would of never thought of that. Thanks!