UIColor

public extension UIColor

An extension to test if colors meet standard accessibility contrast requirements.

Accessibility Compliance

  • A requirement defining how the visual presentation of text achieves a minimum contrast ratio to pass the accessibility specification - https://www.w3.org/TR/2008/REC-WCAG20-20081211/#visual-audio-contrast-contrast

    See more

    Declaration

    Swift

    enum AccessibilityRequirement
  • Tests if two contrasting colors pass a provided accessibility requirement.

    Declaration

    Swift

    static func isCompliant(with requirement: AccessibilityRequirement, testing foreground: UIColor, against background: UIColor) -> Bool

    Parameters

    requirement

    The accessibility requirement to test.

    foreground

    The foreground color to contrast against the background color.

    background

    The background color to contrast against the foreground color.

    Return Value

    true if the two contrasting colors pass the accessibility requirement.

  • Tests if the current color, contrasting with another color, passes a provided accessibility requirement.

    Declaration

    Swift

    func isCompliant(with requirement: AccessibilityRequirement, against background: UIColor) -> Bool

    Parameters

    requirement

    The accessibility requirement to test.

    background

    The background color to contrast against the current color.

    Return Value

    true if the two contrasting colors pass the accessibility requirement.

Contrast Ratio

  • Returns the contrast ratio between two colors based on their luminance values.

    Declaration

    Swift

    static func contrastRatio(between color1: UIColor, and color2: UIColor) -> CGFloat

    Parameters

    color1

    The first color to compare to the second.

    color2

    The second color to compare to the first.

    Return Value

    The contrast ratio between the two colors.

  • Returns the contrast ratio of the color compared to another color based on their luminance values.

    Declaration

    Swift

    func contrastRatio(to color: UIColor) -> CGFloat

    Parameters

    color

    The other color to compare.

    Return Value

    The contrast ratio between the two colors.

  • Compares the contrast ratio of the color to two others and returns which of the two colors has the higher ratio.

    Declaration

    Swift

    func higherContrastingColor(between color1: UIColor, and color2: UIColor) -> UIColor

    Parameters

    color1

    The first color to compare to the base color.

    color2

    The second color to compare to the base color.

    Return Value

    The color with the higher contrast ratio compared to the base color.

  • Compares the contrast ratio of the color to an array of others and returns which color in the array has the highest ratio.

    Declaration

    Swift

    func highestContrastingColor(between colors: [UIColor]) -> UIColor?

    Parameters

    colors

    An array of colors to compare to the base color.

    Return Value

    The color with the highest contrast ratio compared to the base color.

  • Compares the contrast ratio of the color to two others and returns which of the two colors has the lower ratio.

    Declaration

    Swift

    func lowerContrastingColor(between color1: UIColor, and color2: UIColor) -> UIColor

    Parameters

    color1

    The first color to compare to the base color.

    color2

    The second color to compare to the base color.

    Return Value

    The color with the lower contrast ratio compared to the base color.

  • Compares the contrast ratio of the color to an array of others and returns which color in the array has the lowest ratio.

    Declaration

    Swift

    func lowestContrastingColor(between colors: [UIColor]) -> UIColor?

    Parameters

    colors

    An array of colors to compare to the base color.

    Return Value

    The color with the lowest contrast ratio compared to the base color.

Luminance

  • The relative luminance of the color, measured according to the HSL color model.

    Declaration

    Swift

    var relativeLuminance: CGFloat { get }
  • The perceived brightness of the color, measured according to the HSP color model - http://alienryderflex.com/hsp.html

    Declaration

    Swift

    var perceivedBrightness: CGFloat { get }
  • Returns true if the color is considered light according to its perceived brightness.

    Declaration

    Swift

    var isLight: Bool { get }
  • Returns true if the color is considered dark according to its perceived brightness.

    Declaration

    Swift

    var isDark: Bool { get }

Harmonies

  • A set of harmonized color schemes created from a base color.

    See more

    Declaration

    Swift

    struct Harmony
  • A set of harmonized color schemes based on the base color.

    Declaration

    Swift

    var harmonies: Harmony { get }

Hue Adjustment

  • Returns a new instance of the color with an adjusted hue.

    Declaration

    Swift

    func adjustingHue(by degrees: CGFloat) -> UIColor

    Parameters

    degrees

    The amount to adjust the hue, in the range [-360°, 360°].

    Return Value

    The hue adjusted color.

  • The color opposite on the color wheel, equivalant to adjusting the hue by 180°.

    Declaration

    Swift

    var complement: UIColor { get }
  • Returns true if the color falls on the cool side of the color wheel (90° ≤ hue < 270°).

    Declaration

    Swift

    var isCool: Bool { get }
  • Returns true if the color falls on the warm side of the color wheel (90° > hue ≥ 270°).

    Declaration

    Swift

    var isWarm: Bool { get }

Inversion

  • The negative of the color, produced by inverting the RGB values.

    Declaration

    Swift

    var inverted: UIColor { get }

Lightness

  • Returns a new instance of the color with increased lightness.

    Declaration

    Swift

    func lighter(percent: CGFloat = 0.1) -> UIColor

    Parameters

    percent

    The amount to lighten the color, in the range [0, 1].

    Return Value

    The lighter color.

  • Returns a new instance of the color with decreased lightness.

    Declaration

    Swift

    func darker(percent: CGFloat = 0.1) -> UIColor

    Parameters

    percent

    The amount to darken the color, in the range [0, 1].

    Return Value

    The darker color.

Saturation

  • Returns a new instance of the color with increased saturation.

    Declaration

    Swift

    func saturated(percent: CGFloat = 0.1) -> UIColor

    Parameters

    percent

    The amount to saturate the color, in the range [0, 1].

    Return Value

    The saturated color.

  • Returns a new instance of the color with decreased saturation.

    Declaration

    Swift

    func desaturated(percent: CGFloat = 0.1) -> UIColor

    Parameters

    percent

    The amount to desaturate the color, in the range [0, 1].

    Return Value

    The desaturated color.

  • Returns a new instance of the color with 0% saturation.

    Declaration

    Swift

    func grayscaled() -> UIColor

    Return Value

    The grayscaled color.

Averaging

  • Returns the average color of an array of colors.

    This function accounts for human visual perception by squaring the RGB values first, then dividing by the number of colors and taking the square root. Here is a video that explains it further: https://www.youtube.com/watch?v=LKnqECcg6Gw.

    Declaration

    Swift

    static func average(of colors: [UIColor]) -> UIColor

    Parameters

    colors

    The array of colors to average.

    Return Value

    The average color.

  • Returns the average of two colors.

    This function accounts for human visual perception by squaring the RGB values first, then dividing by two and taking the square root. Here is a video that explains it further: https://www.youtube.com/watch?v=LKnqECcg6Gw.

    Declaration

    Swift

    static func average(of color1: UIColor, and color2: UIColor) -> UIColor

    Parameters

    color1

    The first color to average with the second.

    color2

    The second color to average with the first.

    Return Value

    The average color.

Web Safe

  • The nearest web safe color to the current color. All web safe colors have RGB component values of 0, 51, 102, 153, 204, or 255 (20% intervals).

    Declaration

    Swift

    var webSafe: UIColor { get }

Tertiary Colors

  • A color object whose RGB values are 0.0, 0.5, and 1.0 and whose alpha value is 1.0.

    Declaration

    Swift

    open class var azure: UIColor { get }
  • A color object whose RGB values are 0.5, 0.0, and 1.0 and whose alpha value is 1.0.

    Declaration

    Swift

    open class var violet: UIColor { get }
  • A color object whose RGB values are 1.0, 0.0, and 0.5 and whose alpha value is 1.0.

    Declaration

    Swift

    open class var rose: UIColor { get }
  • A color object whose RGB values are 0.5, 1.0, and 0.0 and whose alpha value is 1.0.

    Declaration

    Swift

    open class var chartreuse: UIColor { get }
  • A color object whose RGB values are 0.0, 1.0, and 0.5 and whose alpha value is 1.0.

    Declaration

    Swift

    open class var springGreen: UIColor { get }

Color Wheel

  • The colors that define the color wheel.

    See more

    Declaration

    Swift

    struct ColorWheel

Gradients

  • Generates an array of colors between a start and end color. The colors are produced by mixing the start color with the end color with evenly distributed stops.

    Declaration

    Swift

    static func gradient(between start: UIColor, and end: UIColor, stops: Int = 5) -> [UIColor]

    Parameters

    start

    The starting color of the gradient.

    end

    The ending color of the gradient.

    stops

    The number of colors to be produced, including the start and end. For example, 5 stops would return the following: [start, 25%, 50%, 75%, end]

    Return Value

    The array of colors forming the gradient.

  • Generates an array of colors between a start and end color. The colors are produced by mixing the start color with the end color with a custom array of distributed stops. This function can be used to generate a gradient that is not evenly distributed.

    Declaration

    Swift

    static func gradient(between start: UIColor, and end: UIColor, customStops: [CGFloat]) -> [UIColor]

    Parameters

    start

    The color at a stop of 0%.

    end

    The color at a stop of 100%.

    customStops

    The array of custom stop percentages. The start and end color are not included by default; therefore, a value of 0.0 and 1.0 should be included in the array, if desired.

    Return Value

    The array of colors forming the gradient.

Mixing

  • Returns a mixture of two colors with a given weight.

    Declaration

    Swift

    static func mixing(_ first: UIColor, with second: UIColor, weight: CGFloat = 0.5) -> UIColor

    Parameters

    first

    The first color to be mixed with the second color.

    second

    The second color to be mixed with the first color.

    weight

    The ratio of the second color mixed with the first color. The default value of 0.5 indicates 50% of each color is mixed together. A value of 0.25 indicates 25% of the second color is mixed with 75% of the first color.

    Return Value

    The mixed color.

  • Returns a mixture of the source color with another color.

    Declaration

    Swift

    func mixed(with color: UIColor, weight: CGFloat = 0.5) -> UIColor

    Parameters

    color

    The other color to be mixed with the source color.

    weight

    The ratio of the second color (other) mixed with the first color (source). The default value of 0.5 indicates 50% of each color is mixed together. A value of 0.25 indicates 25% of the second color is mixed with 75% of the first color.

    Return Value

    The mixed color.

Mixing Model

  • A model that describes how colors are mixed together to form all other colors.

    See more

    Declaration

    Swift

    enum MixingModel

Shade, Tint, Tone

  • Returns a mixture of the color with black, decreasing lightness.

    Declaration

    Swift

    func shade(percent: CGFloat = 0.1) -> UIColor

    Parameters

    percent

    The amount of black mixed with the color, in the range [0, 1].

    Return Value

    The shaded color after mixing with black.

  • Returns a mixture of the color with white, increasing lightness.

    Declaration

    Swift

    func tint(percent: CGFloat = 0.1) -> UIColor

    Parameters

    percent

    The amount of white mixed with the color, in the range [0, 1].

    Return Value

    The tinted color after mixing with white.

  • Returns a mixture of the color with gray, decreasing saturation.

    Declaration

    Swift

    func tone(percent: CGFloat = 0.1) -> UIColor

    Parameters

    percent

    The amount of gray mixed with the color, in the range [0, 1].

    Return Value

    The toned color after mixing with gray.

Randomization

  • Returns a color with random component values.

    Declaration

    Swift

    static func random(includeAlpha: Bool = false) -> UIColor

    Parameters

    includeAlpha

    Indicates whether the alpha component should be randomized. If false, the color will have an alpha value of 1.0.

    Return Value

    The random color.

  • Returns a set of unique colors with random component values.

    Declaration

    Swift

    static func randomSet(of amount: Int, includeAlpha: Bool = false) -> Set<UIColor>

    Parameters

    amount

    The amount of random colors to be generated.

    includeAlpha

    Indicates whether the alpha components should be randomized. If false, the colors will have an alpha value of 1.0.

    Return Value

    The random set of colors.

ARGB

  • The ARGB (alpha, red, green, blue) components of a color, in the range [0, 255].

    See more

    Declaration

    Swift

    struct ARGB : Hashable
  • The ARGB (alpha, red, green, blue) components of the color, in the range [0, 255].

    Declaration

    Swift

    var argb: ARGB { get }
  • Initializes a color from ARGB (alpha, red, green, blue) components.

    Declaration

    Swift

    convenience init(_ argb: ARGB)

    Parameters

    argb

    The components used to initialize the color.

CIELAB

  • The CIELAB components of a color - lightness (L) and chromaticity (a,b).

    See more

    Declaration

    Swift

    struct CIELAB : Hashable
  • Lab

    The CIELAB components of the color using a d65 illuminant and 2° standard observer.

    Declaration

    Swift

    var Lab: CIELAB { get }
  • The CIELAB components of the color using a given illuminant and standard observer.

    Declaration

    Swift

    func Lab(illuminant: Illuminant, observer: StandardObserver) -> CIELAB

    Parameters

    illuminant

    The illuminant used to calculate tristimulus values.

    observer

    The standard observer used to calculate tristimulus values.

    Return Value

    The CIELAB components of the color.

  • Initializes a color from CIELAB components.

    Declaration

    Swift

    convenience init(_ Lab: CIELAB,
                     illuminant: Illuminant = .d65,
                     observer: StandardObserver = .two,
                     alpha: CGFloat = 1.0)

    Parameters

    Lab

    The components used to initialize the color.

    illuminant

    The illuminant used to calculate tristimulus values.

    observer

    The standard observer used calculate tristimulus values.

    alpha

    The alpha value of the color.

CIELCh°

  • The CIELCh° components of a color - lightness (L), chroma ©, and hue (h).

    See more

    Declaration

    Swift

    struct CIELCh : Hashable

CIELCh°(ab)

  • The CIELCh°(ab) components of the color using a d65 illuminant and 2° standard observer.

    Declaration

    Swift

    var LCh_ab: CIELCh { get }
  • The CIELCh°(ab) components of the color using a given illuminant and standard observer.

    Declaration

    Swift

    func LCh_ab(illuminant: Illuminant, observer: StandardObserver) -> CIELCh

    Parameters

    illuminant

    The illuminant used to calculate tristimulus values.

    observer

    The standard observer used to calculate tristimulus values.

    Return Value

    The CIELCh°(ab) components of the color.

  • Initializes a color from CIELCh°(ab) components.

    Declaration

    Swift

    convenience init(ab LCh: CIELCh,
                     illuminant: Illuminant = .d65,
                     observer: StandardObserver = .two,
                     alpha: CGFloat = 1.0)

    Parameters

    LCh

    The components used to initialize the color.

    illuminant

    The illuminant used to calculate tristimulus values.

    observer

    The standard observer used calculate tristimulus values.

    alpha

    The alpha value of the color.

CIELCh°(uv)

  • The CIELCh°(uv) components of the color using a d65 illuminant and 2° standard observer.

    Declaration

    Swift

    var LCh_uv: CIELCh { get }
  • The CIELCh°(uv) components of the color using a given illuminant and standard observer.

    Declaration

    Swift

    func LCh_uv(illuminant: Illuminant, observer: StandardObserver) -> CIELCh

    Parameters

    illuminant

    The illuminant used to calculate tristimulus values.

    observer

    The standard observer used to calculate tristimulus values.

    Return Value

    The CIELCh°(uv) components of the color.

  • Initializes a color from CIELCh°(uv) components.

    Declaration

    Swift

    convenience init(uv LCh: CIELCh,
                     illuminant: Illuminant = .d65,
                     observer: StandardObserver = .two,
                     alpha: CGFloat = 1.0)

    Parameters

    LCh

    The components used to initialize the color.

    illuminant

    The illuminant used to calculate tristimulus values.

    observer

    The standard observer used calculate tristimulus values.

    alpha

    The alpha value of the color.

CIELUV

  • The CIELUV components of a color - lightness (L) and chromaticity (u,v).

    See more

    Declaration

    Swift

    struct CIELUV : Hashable
  • Luv

    The CIELUV components of the color using a d65 illuminant and 2° standard observer.

    Declaration

    Swift

    var Luv: CIELUV { get }
  • The CIELUV components of the color using a given illuminant and standard observer.

    Declaration

    Swift

    func Luv(illuminant: Illuminant, observer: StandardObserver) -> CIELUV

    Parameters

    illuminant

    The illuminant used to calculate tristimulus values.

    observer

    The standard observer used to calculate tristimulus values.

    Return Value

    The CIELUV components of the color.

  • Initializes a color from CIELUV components.

    Declaration

    Swift

    convenience init(_ Luv: CIELUV,
                     illuminant: Illuminant = .d65,
                     observer: StandardObserver = .two,
                     alpha: CGFloat = 1.0)

    Parameters

    Luv

    The components used to initialize the color.

    illuminant

    The illuminant used to calculate tristimulus values.

    observer

    The standard observer used calculate tristimulus values.

    alpha

    The alpha value of the color.

CIE 1960 UCS

  • The CIE 1960 UCS components of a color - (u,v) chromaticity coordinates.

    See more

    Declaration

    Swift

    struct CIEUCS : Hashable
  • ucs

    The CIE 1960 UCS components of the color.

    Declaration

    Swift

    var ucs: CIEUCS { get }
  • Initializes a color from CIE 1960 UCS components.

    Declaration

    Swift

    convenience init(_ ucs: CIEUCS, luminance: CGFloat = 1.0, alpha: CGFloat = 1.0)

    Parameters

    ucs

    The components used to initialize the color.

    luminance

    The luminance value of the color.

    alpha

    The alpha value of the color.

CIE 1964 UVW

  • The CIE 1964 UVW components of a color - chromaticity (U,V) and lightness (W).

    See more

    Declaration

    Swift

    struct CIEUVW : Hashable
  • uvw

    The CIE 1964 UVW components of the color using a d65 illuminant and 2° standard observer.

    Declaration

    Swift

    var uvw: CIEUVW { get }
  • The CIE 1964 UVW components of the color using a given illuminant and standard observer.

    Declaration

    Swift

    func uvw(illuminant: Illuminant, observer: StandardObserver) -> CIEUVW

    Parameters

    illuminant

    The illuminant used to calculate tristimulus values.

    observer

    The standard observer used to calculate tristimulus values.

    Return Value

    The CIE 1964 UVW components of the color.

  • Initializes a color from CIE 1964 UVW components.

    Declaration

    Swift

    convenience init(_ uvw: CIEUVW,
                     illuminant: Illuminant = .d65,
                     observer: StandardObserver = .two,
                     alpha: CGFloat = 1.0)

    Parameters

    uvw

    The components used to initialize the color.

    illuminant

    The illuminant used to calculate tristimulus values.

    observer

    The standard observer used calculate tristimulus values.

    alpha

    The alpha value of the color.

CIE 1931 XYZ

  • The CIE 1931 XYZ components of a color - luminance (Y) and chromaticity (X,Z).

    See more

    Declaration

    Swift

    struct CIEXYZ : Hashable
  • XYZ

    The CIE 1931 XYZ components of the color.

    Declaration

    Swift

    var XYZ: CIEXYZ { get }
  • Initializes a color from CIE 1931 XYZ components.

    Declaration

    Swift

    convenience init(_ XYZ: CIEXYZ, alpha: CGFloat = 1.0)

    Parameters

    XYZ

    The components used to initialize the color.

    alpha

    The alpha value of the color.

CIE xyY

  • The CIE xyY components of a color - luminance (Y) and chromaticity (x,y).

    See more

    Declaration

    Swift

    struct CIExyY : Hashable
  • xyY

    The CIE xyY components of the color.

    Declaration

    Swift

    var xyY: CIExyY { get }
  • Initializes a color from CIE xyY components.

    Declaration

    Swift

    convenience init(_ xyY: CIExyY, alpha: CGFloat = 1.0)

    Parameters

    xyY

    The components used to initialize the color.

    alpha

    The alpha value of the color.

CMYK

  • The CMYK (cyan, magenta, yellow, black) components of a color, in the range [0, 100%].

    See more

    Declaration

    Swift

    struct CMYK : Hashable
  • The CMYK (cyan, magenta, yellow, black) components of the color, in the range [0, 100%].

    Declaration

    Swift

    var cmyk: CMYK { get }
  • Initializes a color from CMYK (cyan, magenta, yellow, black) components.

    Declaration

    Swift

    convenience init(_ cmyk: CMYK, alpha: CGFloat = 1.0)

    Parameters

    cmyk

    The components used to initialize the color.

    alpha

    The alpha value of the color.

HSB

  • HSB

    The HSB (hue, saturation, brightness) components of a color.

    See more

    Declaration

    Swift

    struct HSB : Hashable
  • hsb

    The HSB (hue, saturation, brightness) components of the color.

    Declaration

    Swift

    var hsb: HSB { get }
  • Initializes a color from HSB (hue, saturation, brightness) components.

    Declaration

    Swift

    convenience init(_ hsb: HSB, alpha: CGFloat = 1.0)

    Parameters

    hsb

    The components used to initialize the color.

    alpha

    The alpha value of the color.

HSI

  • HSI

    The HSI (hue, saturation, intensity) components of a color.

    See more

    Declaration

    Swift

    struct HSI : Hashable
  • hsi

    The HSI (hue, saturation, intensity) components of the color.

    Declaration

    Swift

    var hsi: HSI { get }
  • Initializes a color from HSI (hue, saturation, intensity) components.

    Declaration

    Swift

    convenience init(_ hsi: HSI, alpha: CGFloat = 1.0)

    Parameters

    hsi

    The components used to initialize the color.

    alpha

    The alpha value of the color.

HSL

  • HSL

    The HSL (hue, saturation, lightness) components of a color.

    See more

    Declaration

    Swift

    struct HSL : Hashable
  • hsl

    The HSL (hue, saturation, lightness) components of the color.

    Declaration

    Swift

    var hsl: HSL { get }
  • Initializes a color from HSL (hue, saturation, lightness) components.

    Declaration

    Swift

    convenience init(_ hsl: HSL, alpha: CGFloat = 1.0)

    Parameters

    hsl

    The components used to initialize the color.

    alpha

    The alpha value of the color.

HSV

  • HSV

    The HSV (hue, saturation, value) components of a color.

    See more

    Declaration

    Swift

    struct HSV : Hashable
  • hsv

    The HSV (hue, saturation, value) components of the color.

    Declaration

    Swift

    var hsv: HSV { get }
  • Initializes a color from HSV (hue, saturation, value) components.

    Declaration

    Swift

    convenience init(_ hsv: HSV, alpha: CGFloat = 1.0)

    Parameters

    hsv

    The components used to initialize the color.

    alpha

    The alpha value of the color.

Hex

  • Initializes a color from a hexadecimal integer in the RGB format (RRGGBB), e.g., 0xffff00.

    Declaration

    Swift

    convenience init(hex: Int, alpha: CGFloat = 1.0)

    Parameters

    hex

    The hexadecimal value of the color.

    alpha

    The alpha value of the color.

  • Initializes a color from a hexadecimal string in the RGB format (RRGGBB), e.g., “#ffff00”.

    Declaration

    Swift

    convenience init?(hex: String, alpha: CGFloat = 1.0)

    Parameters

    hex

    The hexadecimal string value of the color.

    alpha

    The alpha value of the color.

  • hex

    The hexadecimal integer value of the color in the RGB format (RRGGBB), e.g., 0xffff00.

    Declaration

    Swift

    var hex: Int { get }
  • The hexadecimal string value of the color in the RGB format (RRGGBB), e.g., “#ffff00”.

    Declaration

    Swift

    var hexString: String { get }

Hex (ARGB)

  • Initializes a color from a hexadecimal integer in the ARGB format (AARRGGBB), e.g., 0x80ffff00.

    Declaration

    Swift

    convenience init(hex_ARGB hex: Int)

    Parameters

    hex

    The hexadecimal value of the color.

  • Initializes a color from a hexadecimal string in the ARGB format (AARRGGBB), e.g., “#80ffff00”.

    Declaration

    Swift

    convenience init?(hex_ARGB hex: String)

    Parameters

    hex

    The hexadecimal string value of the color.

  • The hexadecimal integer value of the color in the ARGB format (AARRGGBB), e.g., 0x80ffff00.

    Declaration

    Swift

    var hex_ARGB: Int { get }
  • The hexadecimal string value of the color in the ARGB format (AARRGGBB), e.g., “#80ffff00”.

    Declaration

    Swift

    var hexString_ARGB: String { get }

Hex (RGBA)

  • Initializes a color from a hexadecimal integer in the RGBA format (RRGGBBAA), e.g., 0xffff0080.

    Declaration

    Swift

    convenience init(hex_RGBA hex: Int)

    Parameters

    hex

    The hexadecimal value of the color.

  • Initializes a color from a hexadecimal string in the RGBA format (RRGGBBAA), e.g., “#ffff0080”.

    Declaration

    Swift

    convenience init?(hex_RGBA hex: String)

    Parameters

    hex

    The hexadecimal string value of the color.

  • The hexadecimal integer value of the color in the RGBA format (RRGGBBAA), e.g., 0xffff0080.

    Declaration

    Swift

    var hex_RGBA: Int { get }
  • The hexadecimal string value of the color in the RGBA format (RRGGBBAA), e.g., “#ffff0080”.

    Declaration

    Swift

    var hexString_RGBA: String { get }

Hunter Lab

  • The Hunter Lab components of a color - lightness (L) and chromaticity (a,b).

    See more

    Declaration

    Swift

    struct HunterLab : Hashable
  • The Hunter Lab components of the color using a d65 illuminant and 2° standard observer.

    Declaration

    Swift

    var hunterLab: HunterLab { get }
  • The Hunter Lab components of the color using a given illuminant and standard observer.

    Declaration

    Swift

    func hunterLab(illuminant: Illuminant, observer: StandardObserver) -> HunterLab

    Parameters

    illuminant

    The illuminant used to calculate tristimulus values.

    observer

    The standard observer used to calculate tristimulus values.

    Return Value

    The Hunter Lab components of the color.

  • Initializes a color from Hunter Lab components.

    Declaration

    Swift

    convenience init(_ hunterLab: HunterLab,
                     illuminant: Illuminant = .d65,
                     observer: StandardObserver = .two,
                     alpha: CGFloat = 1.0)

    Parameters

    hunterLab

    The components used to initialize the color.

    illuminant

    The illuminant used to calculate tristimulus values.

    observer

    The standard observer used calculate tristimulus values.

    alpha

    The alpha value of the color.

Linear RGB

  • A set of non-gamma corrected linear RGB values, in the range [0, 1].

    Declaration

    Swift

    typealias LinearRGB = (r: CGFloat, g: CGFloat, b: CGFloat)
  • The inverse companded sRGB components to get non-gamma corrected linear values, in the range [0, 1].

    Declaration

    Swift

    var linearRGB: LinearRGB { get }
  • Initializes an sRGB gamma corrected color from linear RGB values.

    Declaration

    Swift

    convenience init(linear rgb: LinearRGB, alpha: CGFloat = 1.0)

    Parameters

    rgb

    The linear RGB values to be gamma corrected.

    alpha

    The alpha value of the color.

RGB

  • RGB

    The RGB (red, green, blue) components of a color, in the range [0, 255].

    See more

    Declaration

    Swift

    struct RGB : Hashable
  • rgb

    The RGB (red, green, blue) components of the color, in the range [0, 255].

    Declaration

    Swift

    var rgb: RGB { get }
  • Initializes a color from RGB (red, green, blue) components.

    Declaration

    Swift

    convenience init(_ rgb: RGB, alpha: CGFloat = 1.0)

    Parameters

    rgb

    The components used to initialize the color.

    alpha

    The alpha value of the color.

RGBA

  • The RGBA (red, green, blue, alpha) components of a color, in the range [0, 255].

    See more

    Declaration

    Swift

    struct RGBA : Hashable
  • The RGBA (red, green, blue, alpha) components of a color, in the range [0, 255].

    Declaration

    Swift

    var rgba: RGBA { get }
  • Initializes a color from RGBA (red, green, blue, alpha) components.

    Declaration

    Swift

    convenience init(_ rgba: RGBA)

    Parameters

    rgba

    The components used to initialize the color.

Y′CbCr

  • The Y′CbCr components of a color - luma (Y′) and chroma (Cb,Cr).

    See more

    Declaration

    Swift

    struct YCbCr : Hashable
  • The Y′CbCr components of the color using Rec.601 (standard-definition) encoding.

    Declaration

    Swift

    var yCbCr: YCbCr { get }
  • The Y′CbCr components of the color using a given encoding.

    Declaration

    Swift

    func yCbCr(_ encoding: SignalEncoding) -> YCbCr

    Parameters

    encoding

    The signal encoding with which the components are derived.

    Return Value

    The Y′CbCr components of the color.

  • Initializes a color from Y′CbCr components.

    Declaration

    Swift

    convenience init(_ yCbCr: YCbCr,
                     encoding: SignalEncoding = .rec601,
                     alpha: CGFloat = 1.0)

    Parameters

    yCbCr

    The components used to initialize the color.

    encoding

    The signal encoding with which the components were derived.

    alpha

    The alpha value of the color.

Y′IQ

  • YIQ

    The Y′IQ components of a color - luma (Y′) and chroma (I,Q).

    See more

    Declaration

    Swift

    struct YIQ : Hashable
  • yiq

    The Y′IQ components of the color using Rec.601 (standard-definition) encoding.

    Declaration

    Swift

    var yiq: YIQ { get }
  • The Y′IQ components of the color using a given encoding.

    Declaration

    Swift

    func yiq(_ encoding: SignalEncoding) -> YIQ

    Parameters

    encoding

    The signal encoding with which the components are derived.

    Return Value

    The Y′IQ components of the color.

  • Initializes a color from Y′IQ components.

    Declaration

    Swift

    convenience init(_ yiq: YIQ,
                     encoding: SignalEncoding = .rec601,
                     alpha: CGFloat = 1.0)

    Parameters

    yiq

    The components used to initialize the color.

    encoding

    The signal encoding with which the components were derived.

    alpha

    The alpha value of the color.

Y′PbPr

  • The Y′PbPr components of a color - luma (Y′) and chroma (Pb,Pr).

    See more

    Declaration

    Swift

    struct YPbPr : Hashable
  • The Y′PbPr components of the color using Rec.601 (standard-definition) encoding.

    Declaration

    Swift

    var yPbPr: YPbPr { get }
  • The Y′PbPr components of the color using a given encoding.

    Declaration

    Swift

    func yPbPr(_ encoding: SignalEncoding) -> YPbPr

    Parameters

    encoding

    The signal encoding with which the components are derived.

    Return Value

    The Y′PbPr components of the color.

  • Initializes a color from Y′PbPr components.

    Declaration

    Swift

    convenience init(_ yPbPr: YPbPr,
                     encoding: SignalEncoding = .rec601,
                     alpha: CGFloat = 1.0)

    Parameters

    yPbPr

    The components used to initialize the color.

    encoding

    The signal encoding with which the components were derived.

    alpha

    The alpha value of the color.

Y′UV

  • YUV

    The Y′UV components of a color - luma (Y′) and chroma (U,V).

    See more

    Declaration

    Swift

    struct YUV : Hashable
  • yuv

    The Y′UV components of the color using Rec.601 (standard-definition) encoding.

    Declaration

    Swift

    var yuv: YUV { get }
  • The Y′UV components of the color using a given encoding.

    Declaration

    Swift

    func yuv(_ encoding: SignalEncoding) -> YUV

    Parameters

    encoding

    The signal encoding with which the components are derived.

    Return Value

    The Y′UV components of the color.

  • Initializes a color from Y′UV components.

    Declaration

    Swift

    convenience init(_ yuv: YUV,
                     encoding: SignalEncoding = .rec601,
                     alpha: CGFloat = 1.0)

    Parameters

    yuv

    The components used to initialize the color.

    encoding

    The signal encoding with which the components were derived.

    alpha

    The alpha value of the color.

Color Model

  • A color model is an abstract mathematical model describing the ways colors can be represented as tuples of numbers, typically as three or four values or color components.

    See more

    Declaration

    Swift

    enum ColorModel

Color Space

  • A color space is a specific organization of colors. In combination with physical device profiling, it allows for reproducible representations of color, in both analog and digital representations. Adding a specific mapping function between a color model and a reference color space establishes a definite “footprint”, known as a gamut, and for a given color model this defines a color space.

    See more

    Declaration

    Swift

    enum ColorSpace

RGBA Components

  • The red component of the color, in the range [0, 1].

    Declaration

    Swift

    var redComponent: CGFloat { get }
  • The green component of the color, in the range [0, 1].

    Declaration

    Swift

    var greenComponent: CGFloat { get }
  • The blue component of the color, in the range [0, 1].

    Declaration

    Swift

    var blueComponent: CGFloat { get }
  • The alpha component of the color, in the range [0, 1].

    Declaration

    Swift

    var alphaComponent: CGFloat { get }
  • The red, green, and blue components of the color, in the range [0, 1].

    Declaration

    Swift

    var rgbComponents: (r: CGFloat, g: CGFloat, b: CGFloat) { get }
  • The red, green, blue, and alpha components of the color, in the range [0, 1].

    Declaration

    Swift

    var rgbaComponents: (r: CGFloat, g: CGFloat, b: CGFloat, a: CGFloat) { get }
  • The alpha, red, green, and blue components of the color, in the range [0, 1].

    Declaration

    Swift

    var argbComponents: (a: CGFloat, r: CGFloat, g: CGFloat, b: CGFloat) { get }
  • Initializes a color from a tuple of RGB components.

    Declaration

    Swift

    convenience init(rgb: (r: CGFloat, g: CGFloat, b: CGFloat), alpha: CGFloat = 1.0)

    Parameters

    rgb

    The components used to initialize the color.

    alpha

    The alpha value of the color.

  • Initializes a color from a tuple of RGBA components.

    Declaration

    Swift

    convenience init(rgba: (r: CGFloat, g: CGFloat, b: CGFloat, a: CGFloat))

    Parameters

    rgba

    The components used to initialize the color.

    alpha

    The alpha value of the color.

  • Initializes a color from a tuple of ARGB components.

    Declaration

    Swift

    convenience init(argb: (a: CGFloat, r: CGFloat, g: CGFloat, b: CGFloat))

    Parameters

    argb

    The components used to initialize the color.

    alpha

    The alpha value of the color.

HSB Components

  • The hue component of the color, in the range [0, 1].

    Declaration

    Swift

    var hueComponent: CGFloat { get }
  • The saturation component of the color, in the range [0, 1].

    Declaration

    Swift

    var saturationComponent: CGFloat { get }
  • The brightness component of the color, in the range [0, 1].

    Declaration

    Swift

    var brightnessComponent: CGFloat { get }
  • The hue, saturation, and brightness components of the color, in the range [0, 1].

    Declaration

    Swift

    var hsbComponents: (h: CGFloat, s: CGFloat, b: CGFloat) { get }
  • Initializes a color from a tuple of HSB components.

    Declaration

    Swift

    convenience init(hsb: (h: CGFloat, s: CGFloat, b: CGFloat), alpha: CGFloat = 1.0)

    Parameters

    hsb

    The components used to initialize the color.

    alpha

    The alpha value of the color.

Grayscale Components

  • The white component of the color, in the range [0, 1].

    Declaration

    Swift

    var whiteComponent: CGFloat { get }

Illuminant

  • A standard illuminant defined by the International Commission on Illumination (CIE) which provides a basis for comparing images or colors recorded under different lighting.

    See more

    Declaration

    Swift

    enum Illuminant

Standard Observer

  • A CIE color-mapping function called the standard observer which represents an average human’s chromatic response while observing an object under an illuminant.

    See more

    Declaration

    Swift

    enum StandardObserver

Pantone

  • The Pantone colors of the year color palette.

    Pantone is a limited liability company best known for its Pantone Matching System (PMS), a proprietary color space used in a variety of industries, notably printing, and some manufacturing of colored paint, fabric, and plastics.

    See more

    Declaration

    Swift

    struct Pantone

Signal Encoding

  • A standard ITU-R Recommendation signal encoding.

    ITU-R Recommendations are the names given to the set of international technical standards developed by the Radiocommunication Sector of the International Telecommunication Union (ITU).

    See more

    Declaration

    Swift

    enum SignalEncoding

Tristimulus

  • Tristimulus system, a system for visually matching a color under standardized conditions against the three primary colors — red, green, and blue; the three results are expressed as X, Y, and Z, respectively, and are called tristimulus values.

    Declaration

    Swift

    typealias Tristimulus = UIColor.CIEXYZ