You’re on the right track, to set the text of the segments in an “NSSegmentedControl” you have to work with the backing “NSSegmentedCell”, which is a subclass of NSCell.
And you would use the setLabel:forSegment: function of either NSSegmentedControl or NSSegmentedCell, as the functions in NSSegmentedControl call the same functions in the NSSegmentedCell anyway, so you might as well directly access the NSCell.
So here’s a simple example that sets the label to the index of the segment.
And the “segmentedControlCell” property is an IB Outlet to the NSSegmentedCell in a xib file.
property segmentedControlCell : missing value
if my segmentedControlCell's segmentCount() > 0 then
repeat with index from 0 to ((my segmentedControlCell's segmentCount()) - 1)
my (segmentedControlCell's setLabel:(index as text) forSegment:(index))
my (segmentedControlCell's setLabel:(0 as text) forSegment:(0))
The segments of the NSSegmentedCell are objects in a zero based array, and you can only set or get certain properties or attributes, but cannot access the segment object directly.
You access the segments by their index number, where the first leftmost one would have an index of 0.
The label of the segments is an NSString, and as Shane has concluded, it cannot be formatted or be an attributed string.
You can have an image as well or instead of a label string.
property app : reference to current application
set segmentedControlImage to my app's NSImage's imageNamed:(my app's NSImageNameBonjour)
my segmentedControlCell's setImage:(segmentedControlImage) forSegment:(0)
I’ve used a standard system image for this example, but it could be any image you want to create.
The NSSegmentedControl is a fairly limited control when it comes to customisation.
The Back and Forward buttons in “Safari” are a NSSegmentedControl, with it’s segmentStyle: NSSegmentStyle property set to NSSegmentStyleSeparated.
So in conclusion, if you want to jazz up a “NSSegmentedControl” you will have to create some snazzy images for the segments.
Hope this helps a bit more.