<!--
{
  "documentType" : "article",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/color-creation",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "Color creation"
}
-->

# Color creation

Load colors from asset catalogs and create colors from raw component values.

## Discussion

Create color objects when you want to use specific colors in your UI, altering the raw component values used by grayscale, RGB, HSB, and CMYK. You can set the specified opacity and RGB component values to create personalized colors that fit your needs. Create colors dynamically by component values changing based on the currently active traits. You can use pattern colors to set the fill or stroke color.

## Topics

### Creating a color from component values

[`colorWithWhite:alpha:`](/documentation/UIKit/UIColor/colorWithWhite:alpha:)

Creates a color object using the specified opacity and grayscale values.

[`colorWithHue:saturation:brightness:alpha:`](/documentation/UIKit/UIColor/colorWithHue:saturation:brightness:alpha:)

Creates a color object using the specified opacity and HSB color space component values.

[`colorWithRed:green:blue:alpha:`](/documentation/UIKit/UIColor/colorWithRed:green:blue:alpha:)

Creates a color object using the specified opacity and RGB component values.

[`colorWithDisplayP3Red:green:blue:alpha:`](/documentation/UIKit/UIColor/colorWithDisplayP3Red:green:blue:alpha:)

Creates a color object using the specified opacity and RGB component values in the Display P3 color space.

[`init(white:alpha:)`](/documentation/UIKit/UIColor/init(white:alpha:))

Creates a color object using the specified opacity and grayscale values.

[`init(hue:saturation:brightness:alpha:)`](/documentation/UIKit/UIColor/init(hue:saturation:brightness:alpha:))

Creates a color object using the specified opacity and HSB color space component values.

[`init(red:green:blue:alpha:)`](/documentation/UIKit/UIColor/init(red:green:blue:alpha:))

Creates a color object using the specified opacity and RGB component values.

[`init(red:green:blue:alpha:exposure:)`](/documentation/UIKit/UIColor/init(red:green:blue:alpha:exposure:))

Generates an HDR color by applying an exposure to the SDR color defined by the red, green, and blue components. The `red`, `green`, and `blue` components have a nominal range of [0..1], `exposure` is a value >= 0. To produce an HDR color, we process the given color in a linear color space, multiplying component values by `2^exposure`. The produced color will have a `contentHeadroom` equal to the linearized exposure value. Each whole value of exposure produces a color that is twice as bright.

[`init(red:green:blue:alpha:linearExposure:)`](/documentation/UIKit/UIColor/init(red:green:blue:alpha:linearExposure:))

Generates an HDR color by applying an exposure to the SDR color defined by the red, green, and blue components. The `red`, `green`, and `blue` components have a nominal range of [0..1], `linearExposure` is a value >= 1. To produce an HDR color, we process the given color in a linear color space, multiplying component values by `linearExposure `. The produced color will have a `contentHeadroom` equal to `linearExposure`. Each doubling of `linearExposure` produces a color that is twice as bright.

[`init(displayP3Red:green:blue:alpha:)`](/documentation/UIKit/UIColor/init(displayP3Red:green:blue:alpha:))

Creates a color object using the specified opacity and RGB component values in the Display P3 color space.

[`init(named:)`](/documentation/UIKit/UIColor/init(named:))

Creates a color object using the information from the named asset.

[`init(named:inBundle:compatibleWithTraitCollection:)`](/documentation/UIKit/UIColor/init(named:inBundle:compatibleWithTraitCollection:))

Creates a color object using the named asset that’s compatible with the specified trait collection.

### Creating a color dynamically

[`colorWithDynamicProvider:`](/documentation/UIKit/UIColor/colorWithDynamicProvider:)

Returns a color object that uses the specified block to generate its color data dynamically.

[`init(dynamicProvider:)`](/documentation/UIKit/UIColor/init(dynamicProvider:))

Creates a color object that uses the specified block to generate its color data dynamically.

### Creating a color from another color object

[`init(_:)`](/documentation/UIKit/UIColor/init(_:))

Creates a color object that encapsulates a SwiftUI color.

[`colorWithCIColor:`](/documentation/UIKit/UIColor/colorWithCIColor:)

Creates a color object that encapsulates a Core Image color.

[`init(ciColor:)`](/documentation/UIKit/UIColor/init(ciColor:)-2z057)

Creates a color object that encapsulates a Core Image color.

[`colorWithCGColor:`](/documentation/UIKit/UIColor/colorWithCGColor:)

Creates a color object using the specified Quartz color reference.

[`init(cgColor:)`](/documentation/UIKit/UIColor/init(cgColor:)-27r9g)

Creates a color object using the specified Quartz color reference.

[`withAlphaComponent(_:)`](/documentation/UIKit/UIColor/withAlphaComponent(_:))

Creates a color object that has the same color space and component values as the receiver, but has the specified alpha component.

### Creating a pattern-based color

[`colorWithPatternImage:`](/documentation/UIKit/UIColor/colorWithPatternImage:)

Creates a color object using the specified image.

[`init(patternImage:)`](/documentation/UIKit/UIColor/init(patternImage:))

Creates a color object using the specified image object.

### Creating a color from a resource

[`init(resource:)`](/documentation/UIKit/UIColor/init(resource:))



---

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)