I’m following a tutorial, the method bellow belongs in a class sub-classed from NSview. It is just drawing a red rectangle. I just can’t figure out how it is doing it. I don’t understand what the set message is doing in [bkgColor set] and how it is effecting the background color?
- (void) drawRect: (NSRect) rect {
NSRect bounds = [self bounds];
NSColor *bkgColor = [NSColor redColor];
[bkgColor set];
[NSBezierPath fillRect: bounds];
}
Thanks!
The
setmethod sets the color of the current drawing context for subsequent drawing commands. Think of it as if you have a box of crayons. If you pick up a red crayon, this is equivalent to[[NSColor redColor] set], so now if you draw lines or shapes, they will be in red.