• 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: How to draw a rectangle in a NSView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to draw a rectangle in a NSView


  • Subject: Re: How to draw a rectangle in a NSView
  • From: Shawn Erickson <email@hidden>
  • Date: Sat, 25 Sep 2004 07:14:54 -0700


On Sep 25, 2004, at 3:19 AM, Peter Karlsson wrote:

Dear list!

I wonder if someone can show me how to draw a rectangle in a NSView? This
is very new to me so I need some help to get started.


I found this example...

NSRect r = NSMakeRect(10, 10, 50, 60);
NSBezierPath *bp = [NSBezierPath bezierPathWithRect:r];
NSColor *color = [NSColor blueColor];
[color set];
[bp stroke];

...but I can not figure out where I select the view to draw on. I do not
want it to autodraw. I want to place the code in an action.

NSView sub-classes (normally) do their drawing in drawRect: which is called as needed in response to setNeedsDisplay: and setNeedsDisplayInRect:. So the action would message the view that a rectangle should drawn and setNeedsDisplayInRect: would also be called for the area of the rect that needs to be drawn.


Anyway drawing is outline in the following conceptual documentation (which is linked from the documentation for NSView)...

<http://developer.apple.com/documentation/Cocoa/Conceptual/DrawViews/ index.html>

Also note that some basic drawing operations exist that can avoid some object creation (at least in theory)...

<http://developer.apple.com/documentation/Cocoa/Reference/ ApplicationKit/ObjC_classic/Functions/AppKitFunctions.html#//apple_ref/ doc/uid/20000695/BAJJABBF>

So your drawing code could look like this...

[[NSColor blueColor] set];
NSFrameRect(NSMakeRect(10, 10, 50, 60);

-Shawn

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >How to draw a rectangle in a NSView (From: "Peter Karlsson" <email@hidden>)

  • Prev by Date: Re: Direct pixel access
  • Next by Date: NSImage doesn't accept background color?
  • Previous by thread: How to draw a rectangle in a NSView
  • Next by thread: Re: How to draw a rectangle in a NSView
  • Index(es):
    • Date
    • Thread