Class

NSBezierPath

An object that can create paths using PostScript-style commands.

Declaration

@interface NSBezierPath : NSObject

Overview

Paths consist of straight and curved line segments joined together. Paths can form recognizable shapes such as rectangles, ovals, arcs, and glyphs; they can also form complex polygons using either straight or curved line segments. A single path can be closed by connecting its two endpoints, or it can be left open.

An NSBezierPath object can contain multiple disconnected paths, whether they are closed or open. Each of these paths is referred to as a subpath. The subpaths of a Bézier path object must be manipulated as a group. The only way to manipulate subpaths individually is to create separate NSBezierPath objects for each.

For a given NSBezierPath object, you can stroke the path’s outline or fill the region occupied by the path. You can also use the path as a clipping region for views or other regions. Using methods of NSBezierPath, you can also perform hit detection on the filled or stroked path. Hit detection is needed to implement interactive graphics, as in rubber banding and dragging operations.

The current graphics context is automatically saved and restored for all drawing operations involving Bézier path objects, so your application does not need to worry about the graphics settings changing across invocations.

Topics

Creating an NSBezierPath Object

+ bezierPath

Creates and returns a new NSBezierPath object.

+ bezierPathWithOvalInRect:

Creates and returns a new NSBezierPath object initialized with an oval path inscribed in the specified rectangle.

+ bezierPathWithRect:

Creates and returns a new NSBezierPath object initialized with a rectangular path.

+ bezierPathWithRoundedRect:xRadius:yRadius:

Creates and returns a new NSBezierPath object initialized with a rounded rectangular path.

bezierPathByFlatteningPath

A flattened version of the path object.

bezierPathByReversingPath

A path containing the reversed contents of the current path object.

Constructing Paths

- moveToPoint:

Moves the receiver’s current point to the specified location.

- lineToPoint:

Appends a straight line to the receiver’s path

- curveToPoint:controlPoint1:controlPoint2:

Adds a Bezier cubic curve to the receiver’s path.

- closePath

Closes the most recently added subpath.

- relativeMoveToPoint:

Moves the receiver’s current point to a new point whose location is the specified distance from the current point.

- relativeLineToPoint:

Appends a straight line segment to the receiver’s path starting at the current point and moving towards the specified point, relative to the current location.

- relativeCurveToPoint:controlPoint1:controlPoint2:

Adds a Bezier cubic curve to the receiver’s path from the current point to a new location, which is specified as a relative distance from the current point.

Appending Common Shapes to a Path

- appendBezierPath:

Appends the contents of the specified path object to the receiver’s path.

- appendBezierPathWithPoints:count:

Appends a series of line segments to the receiver’s path.

- appendBezierPathWithOvalInRect:

Appends an oval path to the receiver, inscribing the oval in the specified rectangle.

- appendBezierPathWithArcFromPoint:toPoint:radius:

Appends an arc to the receiver’s path.

- appendBezierPathWithArcWithCenter:radius:startAngle:endAngle:

Appends an arc of a circle to the receiver’s path.

- appendBezierPathWithArcWithCenter:radius:startAngle:endAngle:clockwise:

Appends an arc of a circle to the receiver’s path.

- appendBezierPathWithGlyph:inFont:

Appends an outline of the specified glyph to the receiver’s path.

Deprecated
- appendBezierPathWithGlyphs:count:inFont:

Appends the outlines of the specified glyphs to the receiver’s path.

Deprecated
- appendBezierPathWithPackedGlyphs:

Appends an array of packed glyphs to the receiver’s path.

Deprecated
- appendBezierPathWithRect:

Appends a rectangular path to the receiver’s path.

- appendBezierPathWithRoundedRect:xRadius:yRadius:

Appends a rounded rectangular path to the receiver’s path.

Accessing the Path Attributes

windingRule

The winding rule used to fill the path.

lineCapStyle

The line cap style for the path.

lineJoinStyle

The line join style for the path.

lineWidth

The width of stroked path lines.

miterLimit

The limit at which miter joins are converted to bevel joins.

flatness

The accuracy with which curves are rendered.

- getLineDash:count:phase:

Returns the line-stroking pattern for the receiver.

- setLineDash:count:phase:

Sets the line-stroking pattern for the receiver.

Configuring the Default Path Attributes

defaultWindingRule

Returns the default winding rule used to fill all paths.

defaultLineCapStyle

Returns the default line cap style for all paths.

defaultLineJoinStyle

Returns the default line join style for all paths.

defaultLineWidth

Returns the default line width for the all paths.

defaultMiterLimit

Returns the default miter limit for all paths.

defaultFlatness

Returns the default flatness value for all paths.

Drawing Paths

- stroke

Draws a line along the receiver’s path using the current stroke color and drawing attributes.

- fill

Paints the region enclosed by the receiver’s path.

+ fillRect:

Fills the specified rectangular path with the current fill color.

+ strokeRect:

Strokes the path of the specified rectangle using the current stroke color and the default drawing attributes.

+ strokeLineFromPoint:toPoint:

Strokes a line between two points using the current stroke color and the default drawing attributes.

+ drawPackedGlyphs:atPoint:

Draws a set of packed glyphs at the specified point in the current coordinate system.

Clipping Paths

- addClip

Intersects the area enclosed by the receiver's path with the clipping path of the current graphics context and makes the resulting shape the current clipping path.

- setClip

Replaces the clipping path of the current graphics context with the area inside the receiver's path.

+ clipRect:

Intersects the specified rectangle with the clipping path of the current graphics context and makes the resulting shape the current clipping path

Hit Detection

- containsPoint:

Returns a Boolean value indicating whether the receiver contains the specified point.

Querying Paths

bounds

The bounding box of the receiver’s path

controlPointBounds

The bounding box of the receiver’s path, including any control points

currentPoint

The receiver’s current point (the trailing point or ending point in the most recently added segment).

empty

A Boolean value indicating whether the path is empty.

Applying Transformations

- transformUsingAffineTransform:

Transforms all points in the receiver using the specified transform.

Accessing Elements of a Path

elementCount

The total number of path elements in the receiver's path.

- elementAtIndex:

Returns the type of path element at the specified index.

- elementAtIndex:associatedPoints:

Gets the element type and (and optionally) the associated points for the path element at the specified index.

- removeAllPoints

Removes all path elements from the receiver, effectively clearing the path.

- setAssociatedPoints:atIndex:

Changes the points associated with the specified path element.

Caching Paths

- cachesBezierPath

Returns a Boolean value indicating whether this object maintains a cached image of its path.

Deprecated
- setCachesBezierPath:

Sets whether the receiver should cache its path information.

Deprecated

Constants

NSBezierPathElement

Basic path element commands.

NSLineJoinStyle

The shape of the joins between connected segments of a stroked path.

NSLineCapStyle

The shape of endpoints for an open path when it is stroked.

NSWindingRule

These constants are used to specify the winding rule a Bezier path should use.

Relationships

Inherits From

See Also

Shapes and Paths

Convenience Functions

Draw rectangles and other primitive shapes using these convenience functions.