0
votes

Everywhere on the internet I can read that to change the background color of a NSView you can just override its method drawRect like this:

- (void)drawRect:(NSRect)rect
{
    [[NSColor yellowColor] set];
    NSRectFill(rect);
}

For example here.

However, in my case, the color is drawn on top of the view (I can't see anymore the content), which is quite logical to me. DrawRect is supposed to draw the view, not just its background.

what am I missing?

2

2 Answers

2
votes

You should call [super drawRect:rect] after filling the background. Otherwise, you're simply replacing everything that would be drawn by the superclass's implementation.

0
votes

The examples you refer to are displaying the subviews of the view above the background.