Re: Setting color to an NSView
Re: Setting color to an NSView
- Subject: Re: Setting color to an NSView
- From: Shawn Erickson <email@hidden>
- Date: Fri, 08 Dec 2006 07:32:30 -0800
On Dec 8, 2006, at 7:09 AM, Alan Smith wrote:
I'd do it like this:
- (void)drawRect:(NSRect)rect
{
rect = [self bounds];
[[NSColor blueColor] set];
[self lockFocus];
[NSBezierPath fillRect: rect];
[self unlockFocus];
}
Perhaps that will fix it? In your code myRect should not be
hard-coded. It's better to use something like bounds to get the rect
you want. Or if you only want to fill a portion of the view use some
math to keep it dynamic.
Humm. You should never need to call lockFocus / unlockFocus on
yourself while in drawRect:. The framework ensures that a correct
graphics context is in place and that your view is locked and focused
on that graphic context before your drawRect: method is called.
Additionally you should never call drawRect: directly.
Review...
<http://developer.apple.com/documentation/Cocoa/Conceptual/
CocoaDrawingGuide/DrawingEnviron/chapter_2_section_6.html>
-Shawn
_______________________________________________
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