Note that there are some explanatory texts on larger screens.

plurals
  1. PONSSegmentedControl Colors
    text
    copied!<p>I'd like to have a subclass of NSSegmentedControl where the various segments are different colors. I've tried subclassing NSSegmentedControl and adding the following code:</p> <pre><code>- (void)drawRect:(NSRect)dirtyRect { NSColor *color = [NSColor redColor]; [color setFill]; NSRectFill(dirtyRect); [super drawRect:dirtyRect]; } </code></pre> <p><img src="https://i.stack.imgur.com/f47Or.png" alt="enter image description here"></p> <p>That looks close except that 1. it colors the whole segmented control the same color, red in this case, and 2. there's a little bit of color bleed over on the edges.</p> <p>I also tried subclassing NSSegmentedCell and adding this:</p> <pre><code>- (void)drawSegment:(NSInteger)segment inFrame:(NSRect)frame withView:(NSView *)controlView { NSColor *color; switch (segment) { case 0: color = [NSColor redColor]; break; case 1: color = [NSColor blueColor]; break; case 2: color = [NSColor greenColor]; break; case 3: color = [NSColor orangeColor]; break; default: break; } [color setFill]; NSRectFill(frame); [super drawSegment:segment inFrame:frame withView:controlView]; } </code></pre> <p><img src="https://i.stack.imgur.com/FlypT.png" alt="enter image description here"></p> <p>This is better in that the various segments are displaying unique colors, however I would hardly consider this acceptable. I want the entire segment to be filled in with the appropriate color for that segment and it would be nice if it had the gradient and shading as in the first screenshot.</p> <p>Please let me know how I can achieve this.</p> <p>Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload