Re: Dynamically update drawRect
Re: Dynamically update drawRect
- Subject: Re: Dynamically update drawRect
- From: Quincey Morris <email@hidden>
- Date: Sun, 27 Dec 2009 04:46:12 -0800
On Dec 27, 2009, at 04:22, proger proger wrote:
> I wrote such code for make NSRect and change color:
>
> (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
> // Insert code here to initialize your application
> NSRect frame = NSMakeRect(10, 10, 100, 100) ;
> [[NSColor blueColor] set];
> [NSBezierPath fillRect:frame];
> [customView setNeedsDisplayInRect:frame];
> }
Your drawing code is in the wrong place. 'applicationDidFinishLaunching:' is a method of the application delegate object, so it should *not* be drawing anything. Also, *this* 'setNeedsDisplayInRect:' call isn't needed, because your window is certainly going to draw itself when it's first displayed.
The drawing code should be in your custom view, something like this:
@implementation MyView
...
- (void) drawRect: (NSRect) partOfViewNeedingToBeDrawn
{
[[NSColor blueColor] set];
[NSBezierPath fillRect: partOfViewNeedingToBeDrawn];
}
...
You *really* should study the documentation some more. This is all explained there, and without a good idea of the way things work in Cocoa, you're going to have a hard time with it.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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