Initializer

init(colorSpace:colorComponents:locations:count:)

Creates a CGGradient object from a color space and the provided color components and locations.

Declaration

init?(colorSpace space: CGColorSpace, colorComponents components: UnsafePointer<CGFloat>, locations: UnsafePointer<CGFloat>?, count: Int)

Parameters

space

The color space to use for the gradient. You cannot use a pattern or indexed color space.

components

The color components for each color that defines the gradient. The components should be in the color space specified by space. If you are unsure of the number of components, you can call the function numberOfComponents.

The number of items in this array should be the product of count and the number of components in the color space. For example, if the color space is an RGBA color space and you want to use two colors in the gradient (one for a starting location and another for an ending location), then you need to provide 8 values in components—red, green, blue, and alpha values for the first color, followed by red, green, blue, and alpha values for the second color.

locations

The location for each color provided in components. Each location must be a CGFloat value in the range of 0 to 1, inclusive. If 0 and 1 are not in the locations array, Quartz uses the colors provided that are closest to 0 and 1 for those locations.

If locations is NULL, the first color in colors is assigned to location 0, the last color incolors is assigned to location 1, and intervening colors are assigned locations that are at equal intervals in between.

count

The number of locations provided in the locations parameters.

Return Value

A CGGradient object.

See Also

Creating Gradient Objects

init?(colorsSpace: CGColorSpace?, colors: CFArray, locations: UnsafePointer<CGFloat>?)

Creates a gradient object from a color space and the provided color objects and locations.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software