If I have a bunch of custom views that I made in IB, how can I set up a background color for each when the app awakesFromNib?
Asked
Active
Viewed 5,554 times
0
-
I've you've made the views in Interface Builder, why not just set the required background colo(u)r there? – John Parker Jan 16 '11 at 12:59
-
1A quick search on Stack Overflow yields two equivalent questions: http://stackoverflow.com/questions/2962790/best-way-to-change-the-background-color-for-an-nsview and http://stackoverflow.com/questions/3781326/subclass-nsview-to-change-background-color – Jan 16 '11 at 13:00
-
@Bavarious Hmm... neither of those questions are particularly epic (or usefully generic) it has to be said. – John Parker Jan 16 '11 at 13:02
-
@middaparka Be that as it may, a good question would have referred to those two questions had the OP done his homework. ;-) – Jan 16 '11 at 13:05
1 Answers
7
In your NSView subclass:
- (void)drawRect:(NSRect)aRect
{
[[NSColor redColor] set];
NSRectFill([self bounds]);
}

Joshua Nozzi
- 60,946
- 14
- 140
- 135