views:

641

answers:

2

I'm building a toolbar that I want to look at least somewhat like Preview's. I want to create the Previous/Next buttons. The way I THINK it's done is with a segmented control, each has an image in the control. The problem is that I can't figure out how to get the labels underneath. I can get ONE label centered under the whole thing, but labeling the segmented control, But I can't get a Next and a Previous label under each part of the control.

What am I missing here?

thanks.

+1  A: 

I'm pretty sure it's a "hack"… In Interface Builder (IB), I've managed to recreate the look you'd like to achieve by using, as mentioned, an NSSegmentedControl instance w/ the "Capsule" style. But for its label, I do think it's "just" the string "Previous Next"… (Yep, w/ some space characters as separators :( !)

EDIT: The right answer can be found in the comments; i.e. from Leopard, one can use the NSToolbarItemGroup class to achieve such a result with a segmented control-based toolbar item, as illustrated by code in the documentation here.

(Sorry for the confusion, but as I'm new to Stack Overflow, I don't know whether it's better to remove my comments—and edit my answer—, or leave them for history purposes…)

Frédéric BLANC
Nope, I was wrong, as click+holding the "Previous" toolbar button in Preview only highlights the "Previous"-part of this segmented control. Forget my previous answer, it was not such a basic "hack", I'm still investigating :) !
Frédéric BLANC
OK, so using F-Script Anywhere (http://www.fscript.org/), I managed to inspect the class hierarchy of Preview's "Previous/Next" toolbar item; and… it's actually built using some **private** NSToolbarItemViewer class, from which each button label is represented through a (still **private**) _NSToolbarItemViewerLabelView instance.This won't solve your problem, but that's how Preview manages to label each segment (while the default control available in IB apparently only allows one to label the **whole** control…).
Frédéric BLANC
ok. well, I guess that tells me that failure IS an option... I'm not really that surprised. Looking at the resources in the bundle, I see separate left-capsule and right capsule images (Both selected and unselected), so I was afraid that they had done some sort of manual hack with two separate buttons that just happened to be very close to each other... dang. I'd hoped there was a clever way...
Brian Postow
Oh, oh, once again, I was wrong; or rather, not entirely right ;) ! Look, Brian: I've found what you were looking for, I suppose, and with code too! It's in the NSToolbarItemGroup class reference documentation, in the "Overview" section: http://developer.apple.com/documentation/Cocoa/Reference/NSToolbarItemGroup_Class/Introduction/Introduction.html#//apple_ref/doc/uid/TP40005335-CH3-DontLinkElementID_1. At the very end of it, there's a note re segmented controls. HTH…
Frédéric BLANC
ok, so how would I create an NSToolbarItemGroup? It's not in my palette...
Brian Postow
Indeed, as of Xcode Tools v3.1.3 (the latest version of Apple devtools publicly available to date), one can't visually achieve such a result—since there's no NSToolbarItemGroup control to drag from the "Library" palette of Interface Builder. I'm afraid you'll have to programmatically allocate, initialize, and configure your group before adding it to your toolbar instance…
Frédéric BLANC
+1  A: 

Brian, you may not have seen my n-th comment (sic) to my initial answer (since Stack Overflow hides them in a collapsable section when there are too many of them). But my last comment answered your latest question (i.e. the one re your inability to build an NSToolbarItemGroup from within Interface Builder).

Now that Snow Leopard is released, I can tell you you're still not able to graphically solve your issue by dragging some control from this newer IB's palette. Nope, your only solution is IMHO, as quoted from my Aug. 27 comment, "to programmatically allocate, initialize, and configure your group before adding it to your toolbar instance."

I hope you'll see this new answer ('cause I do think you simply didn't notice my hidden comment…). Wishing you best of luck, hoping you'll be able to solve your problem with those hints, the needed code still being in the Overview section of the NSToolbarItemGroup class reference.

Frédéric BLANC