<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreGraphics",
  "identifier" : "/documentation/CoreGraphics/CGColor",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Core Graphics"
    ],
    "preciseIdentifier" : "c:@T@CGColorRef"
  },
  "title" : "CGColor"
}
-->

# CGColor

A set of components that define a color, with a color space specifying how to interpret them.

```
class CGColor
```

## Overview

`CGColor` is the fundamental data type used internally by Core Graphics to represent colors. `CGColor` objects, and the functions that operate on them, provide a fast and convenient way of managing and setting colors directly, especially colors that are reused (such as black for text).

A color object contains a set of components (such as red, green, and blue) that uniquely define a color, and a color space that specifies how those components should be interpreted.

Color objects provide a fast and convenient way to manage and set colors, especially colors that are used repeatedly. Drawing operations use color objects for setting fill and stroke colors, managing alpha, and setting color with a pattern.

[`CGColor`](/documentation/CoreGraphics/CGColor) is derived from <doc://com.apple.documentation/documentation/CoreFoundation/CFTypeRef> and inherits the properties that all Core Foundation types have in common.

## Topics

### Creating Colors

[`copy()`](/documentation/CoreGraphics/CGColor/copy())

Creates a copy of an existing color.

[`copy(alpha:)`](/documentation/CoreGraphics/CGColor/copy(alpha:))

Creates a copy of an existing color, substituting a new alpha value.

[`init(genericCMYKCyan:magenta:yellow:black:alpha:)`](/documentation/CoreGraphics/CGColor/init(genericCMYKCyan:magenta:yellow:black:alpha:))

Creates a color in the Generic CMYK color space.

[`init(gray:alpha:)`](/documentation/CoreGraphics/CGColor/init(gray:alpha:))

Creates a color in the Generic gray color space.

[`init(genericGrayGamma2_2Gray:alpha:)`](/documentation/CoreGraphics/CGColor/init(genericGrayGamma2_2Gray:alpha:))

Creates a color in the Generic gray color space with a gamma ramp of 2.2.

[`init(red:green:blue:alpha:)`](/documentation/CoreGraphics/CGColor/init(red:green:blue:alpha:))

Creates a color in the Generic RGB color space.

[`init(srgbRed:green:blue:alpha:)`](/documentation/CoreGraphics/CGColor/init(srgbRed:green:blue:alpha:))

Creates a color in the sRGB color space.

[`init(colorSpace:components:)`](/documentation/CoreGraphics/CGColor/init(colorSpace:components:))

Creates a color using a list of intensity values (including alpha) and an associated color space.

[`init(patternSpace:pattern:components:)`](/documentation/CoreGraphics/CGColor/init(patternSpace:pattern:components:))

Creates a color using a list of intensity values (including alpha), a pattern color space, and a pattern.

[`CGColorGetConstantColor`](/documentation/CoreGraphics/CGColorGetConstantColor)

Returns a color object that represents a constant color.

### Retaining and Releasing Color Objects

[`CGColorRelease`](/documentation/CoreGraphics/CGColorRelease)

Decrements the retain count of a color.

[`CGColorRetain`](/documentation/CoreGraphics/CGColorRetain)

Increments the retain count of a color.

### Getting System Colors

[`black`](/documentation/CoreGraphics/CGColor/black)

The black color in the Generic gray color space.

[`white`](/documentation/CoreGraphics/CGColor/white)

The white color in the Generic gray color space.

[`clear`](/documentation/CoreGraphics/CGColor/clear)

The clear color in the Generic gray color space.

[`kCGColorBlack`](/documentation/CoreGraphics/kCGColorBlack)

The black color in the Generic gray color space.

[`kCGColorWhite`](/documentation/CoreGraphics/kCGColorWhite)

The white color in the Generic gray color space.

[`kCGColorClear`](/documentation/CoreGraphics/kCGColorClear)

The clear color in the Generic gray color space.

### Examining a Color

[`CGColorEqualToColor`](/documentation/CoreGraphics/CGColorEqualToColor)

Indicates whether two colors are equal.

[`alpha`](/documentation/CoreGraphics/CGColor/alpha)

Returns the value of the alpha component associated with a color.

[`colorSpace`](/documentation/CoreGraphics/CGColor/colorSpace)

Returns the color space associated with a color.

[`components`](/documentation/CoreGraphics/CGColor/components)

Returns the values of the color components (including alpha) associated with a color.

[`numberOfComponents`](/documentation/CoreGraphics/CGColor/numberOfComponents)

Returns the number of color components (including alpha) associated with a color.

[`pattern`](/documentation/CoreGraphics/CGColor/pattern)

Returns the pattern associated with a color in a pattern color space.

[`CGColorGetComponents`](/documentation/CoreGraphics/CGColorGetComponents)

Returns the values of the color components (including alpha) associated with a color.

### Converting Between Color Spaces

[`conversionTRCSize`](/documentation/CoreGraphics/CGColor/conversionTRCSize)

[`converted(to:intent:options:)`](/documentation/CoreGraphics/CGColor/converted(to:intent:options:))

Creates a new color in a different color space that matches the provided color.

### Working with Core Foundation Types

[`typeID`](/documentation/CoreGraphics/CGColor/typeID)

Returns the Core Foundation type identifier for a color data type.

### Type Properties

[`conversionBlackPointCompensation`](/documentation/CoreGraphics/CGColor/conversionBlackPointCompensation)

An option for whether to apply black point compensation when converting between color profiles.

## See Also

  [Quartz 2D Programming Guide](https://developer.apple.com/library/archive/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/Introduction/Introduction.html#//apple_ref/doc/uid/TP30001066)



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)