Reputation: 303
I want to set the background color of the view without using CALayer.
Please help me out.
Upvotes: 1
Views: 2470
Reputation: 308
You didn't specify if you're talking about AppKit (OSX) or UIKit (iOS). I'll asume you're talking about AppKit because most people coming from UIKit run into this.
NSView does not natively draw a background or background color. You have to either subclass NSView and draw your own color in drawRect
, OR use NSBox provided in AppKit which does draw a background.
If you subclass NSView, then your drawRect
method may look like this:
- (void) drawRect:(NSRect)dirtyRect {
[[NSColor blackColor] setFill];
NSRectFill(dirtyRect);
}
If you decide to use NSBox, then you can set the background color this way:
[myBox setFillColor:[NSColor blackColor]];
Upvotes: 5