cocoanssegmentedcontrol

NSSegmentedControl with bold, italic, and underlined segment


I'm trying to build a segmented control much like the Bold/Italic/Underline control in TextEdit.

Is there a way to set a custom attributed string for each segment? [set attributedStringValue:] on the cell had no effect (there's no way to set per segment anyway).

If I have to resort to custom drawing, how can I reproduce the inset/blue highlight in the selected state?

Example: segmented control example


Solution

  • I think these are all icons you need to pre-create and set in the segmented control. Custom drawing would be another option, but I think simply using 3 icons (plus their hires variants) is more flexible.

    For custom drawing you'd use an NSAttributedString where you set font and color. Draw it twice, once in white with one pixel vertical offset and and once in blue/black.