Class

NSGradient

An object that can draw gradient fill colors

Declaration

@interface NSGradient : NSObject

Overview

This class provides convenience methods for drawing radial or linear (axial) gradients for rectangles and NSBezierPath objects. It also supports primitive methods that let you customize the shape of the gradient fill. A gradient consists of two or more color changes over the range of the gradient shape. When creating a gradient object, you specify the colors and their locations relative to the start and end of the gradient. This combination of color and location is known as a color stop. During drawing, the NSGradient object uses the color stop information to compute color changes for you and passes that information to the Quartz shading functions.

Because the NSGradient class uses Quartz shadings, drawing is handled by computing the colors at a given point mathematically. This technique results in smooth gradients regardless of the resolution of the target device.

For more information about gradients and their appearance, see Gradients in Quartz 2D Programming Guide.

Topics

Initialization

- initWithStartingColor:endingColor:

Initializes a newly allocated gradient object with two colors.

- initWithColors:

Initializes a newly allocated gradient object with an array of colors.

- initWithColorsAndLocations:

Initializes a newly allocated gradient object with a comma-separated list of arguments.

- initWithColors:atLocations:colorSpace:

Initializes a newly allocated gradient object with the specified colors, color locations, and color space.

Primitive Drawing Methods

- drawFromPoint:toPoint:options:

Draws a linear gradient between the specified start and end points.

- drawFromCenter:radius:toCenter:radius:options:

Draws a radial gradient between the specified circles.

Drawing Linear Gradients

- drawInRect:angle:

Fills the specified rectangle with a linear gradient.

- drawInBezierPath:angle:

Fills the specified path with a linear gradient.

Drawing Radial Gradients

- drawInRect:relativeCenterPosition:

Draws a radial gradient starting at the center of the specified rectangle.

- drawInBezierPath:relativeCenterPosition:

Draws a radial gradient starting at the center point of the specified path.

Getting Gradient Properties

colorSpace

The color space of the colors associated with the gradient.

numberOfColorStops

The number of color stops associated with the gradient.

- getColor:location:atIndex:

Returns information about the color stop at the specified index in the receiver’s color array.

- interpolatedColorAtLocation:

Returns the color of the rendered gradient at the specified relative location.

Constants

NSGradientDrawingOptions

Specifies gradient drawing options.

Initializers

Relationships

Inherits From