---
title: CGColor
framework: coregraphics
role: symbol
role_heading: Class
path: coregraphics/cgcolor
---

# CGColor

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

## Declaration

```swift
class CGColor
```

## Overview

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 is derived from CFTypeRef and inherits the properties that all Core Foundation types have in common.

## Topics

### Creating Colors

- [copy()](coregraphics/cgcolor/copy().md)
- [copy(alpha:)](coregraphics/cgcolor/copy(alpha:).md)
- [init(genericCMYKCyan:magenta:yellow:black:alpha:)](coregraphics/cgcolor/init(genericcmykcyan:magenta:yellow:black:alpha:).md)
- [init(gray:alpha:)](coregraphics/cgcolor/init(gray:alpha:).md)
- [init(genericGrayGamma2_2Gray:alpha:)](coregraphics/cgcolor/init(genericgraygamma2_2gray:alpha:).md)
- [init(red:green:blue:alpha:)](coregraphics/cgcolor/init(red:green:blue:alpha:).md)
- [init(srgbRed:green:blue:alpha:)](coregraphics/cgcolor/init(srgbred:green:blue:alpha:).md)
- [init(colorSpace:components:)](coregraphics/cgcolor/init(colorspace:components:).md)
- [init(patternSpace:pattern:components:)](coregraphics/cgcolor/init(patternspace:pattern:components:).md)

### Getting System Colors

- [black](coregraphics/cgcolor/black.md)
- [white](coregraphics/cgcolor/white.md)
- [clear](coregraphics/cgcolor/clear.md)

### Examining a Color

- [alpha](coregraphics/cgcolor/alpha.md)
- [colorSpace](coregraphics/cgcolor/colorspace.md)
- [components](coregraphics/cgcolor/components.md)
- [numberOfComponents](coregraphics/cgcolor/numberofcomponents.md)
- [pattern](coregraphics/cgcolor/pattern.md)

### Converting Between Color Spaces

- [conversionTRCSize](coregraphics/cgcolor/conversiontrcsize.md)
- [converted(to:intent:options:)](coregraphics/cgcolor/converted(to:intent:options:).md)

### Working with Core Foundation Types

- [typeID](coregraphics/cgcolor/typeid.md)

### Type Properties

- [conversionBlackPointCompensation](coregraphics/cgcolor/conversionblackpointcompensation.md)

### Initializers

- [init(headroom:colorSpace:red:green:blue:alpha:)](coregraphics/cgcolor/init(headroom:colorspace:red:green:blue:alpha:).md)

### Instance Properties

- [contentHeadroom](coregraphics/cgcolor/contentheadroom.md)

### Enumerations

- [CGColor.CodingKeys](coregraphics/cgcolor/codingkeys.md)

## Relationships

### Conforms To

- [Copyable](swift/copyable.md)
- [Decodable](swift/decodable.md)
- [Encodable](swift/encodable.md)
- [Equatable](swift/equatable.md)
- [Escapable](swift/escapable.md)
- [Hashable](swift/hashable.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Related Documentation

- [Quartz 2D Programming Guide](apple-archive/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/Introduction.md)

### Colors and Fonts

- [CGColorConversionInfo](coregraphics/cgcolorconversioninfo.md)
- [CGColorSpace](coregraphics/cgcolorspace.md)
- [CGFont](coregraphics/cgfont.md)
