How can I set the appearance of my NSSegmentedControl to match the one of Xcode?

442 Views Asked by At

On Xcode the buttons in the top right corner look like this, depending on their selected state:

Xcode dark mode

I try to replicate it and set the images in my NSSegmentedControl but I only get this

enter image description here

I have played with segButtons.selectedSegmentBezelColor = [NSColor selectedControlColor]; or segButtons.highlighted = YES; but nothing matched. I can't find any other "color" property, in the code or in the inspector.

I'm looking for a solution that would work both on dark or light mode. Thanks in advance!

EDIT:

when using the template: it gets one step closer! but still not blue (even when trying selectedSegmentBezelColor). Much better already though enter image description here


2

There are 2 best solutions below

0
Thomas On BEST ANSWER

The answer is a mix of @Willeke and of mine (but thanks to everyone chiming in, it helped me to not give up).

The image has to be marked as template (which doesn't seem to be possible from the UI) and to mark the segment style as automatic (or TexturedSquare or some other options but not all). Some options are available from the UI but not automatic...

-(void)windowDidLoad {
    [_segmentedCtrl imageForSegment:2].template = YES;
    _segmentedCtrl.segmentStyle = NSSegmentStyleAutomatic;
}
1
Anthony Warner On

In the Attributes panel on the right of the screen, when you select the Segmented Control (in Storyboard), near the top it says "Selected Tint." That's what you're looking for. Change that to whatever color you want.