i would like to be able to set the background of my views. Currently i try to do it by overriding -(void)drawRect:(NSRect)dirtyRect like suggested here, so my custom view looks like this:
@implementation ViewWithBackgroundColor
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// ...
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
- (void)drawRect:(NSRect)dirtyRect
{
[super drawRect:dirtyRect];
[[NSColor greenColor] setFill];
NSRectFill(dirtyRect);
}
@end
when i hit build an run the view appears in the default grey background, but when i resize the window the view appears in the desired green color.
does anybody knows what i am missing? I am not sure if it is relevant, but the view is stored in a nib. I already tried to call setNeedsDisplay:YES in awakeFromNib, but it did not help.
thx in advance, Yevgeniy