CGPath

Immutable and mutable types for graphics paths: mathematical descriptions of shapes or lines to be drawn in a graphics context.

Overview

Neither CGPath nor CGMutablePath define functions to draw a path. To draw a Core Graphics path to a graphics context, you add the path to the graphics context by calling addPath(_:) and then call one of the context’s drawing functions—see CGContext.

Each figure in the graphics path is constructed with a connected set of lines and Bézier curves, called a subpath. A subpath has an ordered set of path elements that represent single steps in the construction of the subpath. (For example, a line segment from one corner of a rectangle to another corner is a path element. Every subpath includes a starting point, which is the first point in the subpath. The path also maintains a current point, which is the last point in the last subpath.

To append a new subpath onto a mutable path, your application typically calls moveTo(_:x:y:) to set the subpath’s starting point and initial current point, followed by a series of "add” calls (such as addLineTo(_:x:y:)) to add line segments and curves to the subpath. As segments or curves are added to the subpath, the subpath’s current point is updated to point to the end of the last segment or curve to be added. The lines and curves of a subpath are always connected, but they are not required to form a closed set of lines. Your application explicitly closes a subpath by calling closeSubpath(). Closing the subpath adds a line segment that terminates at the subpath’s starting point, and also changes how those lines are rendered—for more information see Paths in Quartz 2D Programming Guide.

Symbols

Creating and Managing Paths

init()

Creates a mutable graphics path.

func copy()

Creates an immutable copy of a graphics path.

func copy(using: UnsafePointer<CGAffineTransform>?)

Creates an immutable copy of a graphics path transformed by a transformation matrix.

func mutableCopy()

Creates a mutable copy of an existing graphics path.

func mutableCopy(using: UnsafePointer<CGAffineTransform>?)

Creates a mutable copy of a graphics path transformed by a transformation matrix.

Modifying Core Graphics Paths

func apply(info: UnsafeMutableRawPointer?, function: CGPathApplierFunction)

For each element in a graphics path, calls a custom applier function.

func closeSubpath()

Closes and completes a subpath in a mutable graphics path.

Getting Information about Core Graphics Paths

var boundingBox: CGRect

Returns the bounding box containing all points in a graphics path.

var boundingBoxOfPath: CGRect

Returns the bounding box of a graphics path.

var currentPoint: CGPoint

Returns the current point in a graphics path.

class var typeID: CFTypeID

Returns the Core Foundation type identifier for Core Graphics graphics paths.

var isEmpty: Bool

Indicates whether or not a graphics path is empty.

func isRect(UnsafeMutablePointer<CGRect>?)

Indicates whether or not a graphics path represents a rectangle.

Callbacks

CGPathApplierFunction

Defines a callback function that can view an element in a graphics path.

Data Types

CGPath

An immutable graphics path: a mathematical description of shapes or lines to be drawn in a graphics context.

CGMutablePath

A mutable graphics path: a mathematical description of shapes or lines to be drawn in a graphics context.

CGPathElement

A data structure that provides information about a path element.

Constants

CGPathDrawingMode

Options for rendering a path.

CGPathElementType

The type of element found in a path.

CGLineCap

Styles for rendering the endpoint of a stroked line.

CGLineJoin

Junction types for stroked lines.