aneuryzm
aneuryzm

Reputation: 64874

Is drawRect really changing the background color of a NSView?

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?

Upvotes: 0

Views: 1177

Answers (2)

omz
omz

Reputation: 53561

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.

Upvotes: 2

Mundi
Mundi

Reputation: 80271

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

Upvotes: 0

Related Questions