Re: change NSView background color
Re: change NSView background color
- Subject: Re: change NSView background color
- From: Scott Stevenson <email@hidden>
- Date: Sat, 14 Apr 2007 19:37:49 -0700
On Apr 14, 2007, at 7:17 PM, Ahmet Taha Sakar wrote:
I have the following code:
- (void)drawRect:(NSRect)rect
{
rect = [self bounds];
[NSColor blueColor] set];
[NSBezierPath fillRect: rect];
}
- (void) changeColor: (NSColor *)c
{
[[NSColor blackColor] set];
[NSBezierPath fillRect: [self bounds]];
}
with the drawRect method, I get to have the NSView in blue color.
However, I would like to change the color with an action so I created
changeColor method. But I cant get it to change the color. What am I
missing? thnaks
There are a number of things that the code is missing. Basically, you
need the color to be an instance variable, then call
setNeedsDisplay:YES when the color changes.
All of the drawing (setting the color and filling) should take place
only in the -drawRect: implementation. I think these might help you:
http://cocoadevcentral.com/d/intro_to_quartz/
http://cocoadevcentral.com/d/intro_to_quartz_two/
Best Regards,
- Scott
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden