views:

257

answers:

1

I would like to add a vertical slider to my cocoa menulet application. Just like the vertical slider in the system volume menulet. How do I add this using Interface Builder? And if not with Interface Builder then how?

+2  A: 

This is the sort of thing that will have to be done programmatically (as far as I'm aware). You can create the slider in interface builder and make it vertical and have an outlet to it and all that. You can also create the NSMenuItem and the NSMenu in Interface Builder as well, but you'll have to embed the slider in the menuitem through code. That sort of thing can't be done in IB.

However, from there it's pretty straightforward:

NSSlider * slider = ...; //IBOutlet to your slider
NSMenuItem * item = ...; //IBOutlet to your menuitem
[item setView:slider];

Don't forget to hook up the target/action mechanism of the slider to whomever is supposed to handle the sliding.

Dave DeLong
Thanks! I'm very new at this. I've dragged the slider onto my MainMenu.xib in IB. But where do I get its IBOutlet? (And what goes in the ...). Thanks again
mangledorf
@mangledorf I'd suggest finding a tutorial on how to create IBOutlets. Those are best explained with pictures and (ideally) video. Once you understand those, the `...` should hopefully be obvious.
Dave DeLong
I've figured it out and posted an xcode project with a working slider in menulet:http://www.alecjacobson.com/weblog/?p=1127
mangledorf
@mangledorf it looks good! And it works just fine for me on 10.6
Dave DeLong