Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

< Previous PageNext Page > Hide TOC

Drawing Rectangles

Cocoa provides several functions for drawing rectangles to the current context immediately using the default attributes. These functions use Quartz primitives to draw one or more rectangles quickly, but in a way that may be less precise than if you were to use NSBezierPath. For example, these routines do not apply the current join style to the corners of a framed rectangle.

Table 5-4 lists some of the more commonly used functions for drawing rectangles along with their behaviors. You can use these functions in places where speed is more important than precision. The syntax for each function is provided in a shorthand notation, with parameter types omitted to demonstrate the calling conventions. For a complete list of available functions, and their full syntax, see Application Kit Functions Reference.

Table 5-4  Rectangle frame and fill functions

Function

Description

void NSEraseRect (aRect)

Fills the specified rectangle with white.

void NSFrameRect (aRect)

Draws the frame of the rectangle using the current fill color, the default line width, and the NSCompositeCopy compositing operation.

void NSFrameRectWithWidth (aRect, width)

Draws the frame of the rectangle using the current fill color, the specified width, and the NSCompositeCopy compositing operation.

void NSFrameRectWithWidthUsingOperation (aRect, width, op)

Draws the frame of the rectangle using the current fill color, the specified width, and the specified operation.

void NSRectFill(aRect)

Fills the rectangle using the current fill color and the NSCompositeCopy compositing operation.

void NSRectFillUsingOperation(aRect, op)

Fills the rectangle using the current fill color and specified compositing operation.

void NSRectFillList(rectList, count)

Fills the C-style array of rectangles using the current fill color and the NSCompositeCopy compositing operation.

void NSRectFillListWithColors(rects, colors, count)

Fills the C-style array of rectangles using the corresponding list of colors. Each list must have the same number of entries.

void NSRectFillListUsingOperation(rects, count, op)

Fills the C-style array of rectangles using the current fill color and the specified compositing operation.

void NSRectFillListWithColorsUsingOperation(rects, colors, count, op)

Fills the C-style array of rectangles using the corresponding list of colors and the specified compositing operation. The list of rectangles and list of colors must contain the same number of items.

Important: You may have noticed that the NSFrameRect, NSFrameRectWithWidth, and NSFrameRectWithWidthUsingOperation functions draw the rectangle using the fill color instead of the stroke color. These methods draw the rectangle’s frame by filling four subrectangles, one for each side of the rectangle. This differs from the way NSBezierPath draws rectangles and can sometimes lead to confusion. If your rectangle does not show up the way you expected, check your code to make sure you are setting the drawing color using either the set or setFill method of NSColor.



< Previous PageNext Page > Hide TOC


Last updated: 2007-10-31




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice