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
countand 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 incomponents—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 aCGFloatvalue in the range of 0 to 1, inclusive. If 0 and 1 are not in thelocationsarray, Quartz uses the colors provided that are closest to 0 and 1 for those locations.If
locationsisNULL, the first color incolorsis assigned to location0, the last color incolorsis assigned to location1, and intervening colors are assigned locations that are at equal intervals in between. - count:
The number of locations provided in the
locationsparameters.
Return Value
A CGGradient object.
See Also
Related Documentation
drawRadialGradient(_:startCenter:startRadius:endCenter:endRadius:options:)- Quartz 2D Programming Guide
drawLinearGradient(_:start:end:options:)