2

I've got an NSMenu attached to an NSStatusItem, and inside that NSMenu I have a NSMenuItem for which I've set the view property to an NSSlider object. That works (it got me what I was after) almost.

The result looks like this:

NSSlider in an NSMenu as an NSMenuItem.view http://dl.dropbox.com/u/91596/Screenshots/k8tl.png

The problem is that I'd like the slider to line up with the menu items above it, so it doesn't look so friggin terrible.

I can't find anything in the apple documentation that says anything about being able to set the position of an NSSlider so I assume I'm going to have to wing it by drawing it myself.

Is that a correct assumption? If so, what are some class references/suggested reading links for achieving that result? Or, am I going about this wrong?

While I'm at it - I had to drag the slider in the UI builder to the desired width I wanted - is there any way to programmatically set the width of the slider so it fills up the desired space inside the menu?

Thanks, sorry of these are noob questions - I'm pretty new to ObjC programming.

Jim Rubenstein
  • 6,836
  • 4
  • 36
  • 54
  • The value methods inherited from NSControl. e.g. setFloatValue: – danh Mar 27 '13 at 22:36
  • CGRectDivide() out a suitable frame, then subtract a little from the edges and align it's origin.x with that of the rest of the controls. – CodaFi Mar 27 '13 at 23:06
  • You might want to reconsider your design - as a user I'd *hate* it to fiddle around with sliders within menus... – Jay Mar 28 '13 at 07:04
  • @Jay - you may be right, but the app I'm building is pretty simplistic in nature and just doesn't really have a ton of options/preferences (yet). Making a whole new window or something to allow my user to control the volume of the playback would likely be overkill in this case. Definitely a valid concern though, I'm not thrilled about the idea, but it's the best one I have right now – Jim Rubenstein Mar 28 '13 at 12:48

1 Answers1

2

First make your own NSView. Next, put your NSSlider in that view. If you need special spacing, adjust the slider in the container view. Or, maybe, twiddle in Interface Builder.

Evadne Wu
  • 3,190
  • 1
  • 25
  • 25