Search code examples
xcodecocoaappearancenssegmentedcontrol

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


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



Solution

  • 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;
    }