• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Dynamically update drawRect
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >Dynamically update drawRect (From: proger proger <email@hidden>)
 >Re: Dynamically update drawRect (From: Gideon King <email@hidden>)
 >Re: Dynamically update drawRect (From: Quincey Morris <email@hidden>)
 >Re: Dynamically update drawRect (From: proger proger <email@hidden>)
 >Re: Dynamically update drawRect (From: Quincey Morris <email@hidden>)
 >Re: Dynamically update drawRect (From: proger proger <email@hidden>)

  • Prev by Date: Removing the dragging image
  • Next by Date: Re: resizing NSCollectionView enclosed view items
  • Previous by thread: Re: Dynamically update drawRect
  • Next by thread: dragging to trash folder problems
  • Index(es):
    • Date
    • Thread