0
votes

I am currently trying to set a background color/pattern for an NSView that has a negative bounds origin. The problem is, that it only colors parts of the view (those where x>0 && y>0).

I understand, that I have to draw the background in the -(void)drawRect: function. How can I color the whole view, not just those parts where the coordinates are positive?

NSView Origin: -65, -65 Size: 130, 130

I want to color the whole background

1
Which part of that is the view that's not drawing its whole background, and where is it in the view hierarchy? - Peter Hosey
I have an NSScrollView inside of which there is a Subclass of NSView. The Circle in the middle of the picture is an NSImageView, which is a subview of the NSView subclass. I can display subviews in the negative areas, but no background is drawn. What I did right now is that I created another NSView with the same Size and put it as a subview. While it is not what I imagined, it solves my specific problem. - Tim Bodeit

1 Answers

0
votes

Try using an NSBezierPath object to set the background colour of your view :

NSColor *color; //your background colour
CustomView *view; //this is your view, you should init it with the his own class
[color set];
[NSBezierPath fillRect:[view bounds]]; //sets the given Rect with the set colour

This code should colour all the background with the given colour. Note that you should replace the last line with [path fillRect:[self bounds]] if the code is in the implementation of the class of your view.