Color

A representation of a color that adapts to a given context.

StructureiOS 13.0+macOS 10.15+tvOS 13.0+watchOS 6.0+Color in SwiftUI

Declaration

React
type Color =
  | 'accentColor'
  | 'black'
  | 'blue'
  | 'brown'
  | 'clear'
  | 'cyan'
  | 'gray'
  | 'green'
  | 'indigo'
  | 'mint'
  | 'orange'
  | 'pink'
  | 'primary'
  | 'purple'
  | 'red'
  | 'secondary'
  | 'teal'
  | 'white'
  | 'yellow'
  | { colorSpace?: ColorRGBColorSpace; red: number; green: number; blue: number; opacity?: number; }
  | { colorSpace?: ColorRGBColorSpace; white: number; opacity?: number; }
  | { hue: number; saturation: number; brightness: number; opacity?: number; }
  | { name: string; }
  | ColorResolved
  | ColorResolvedHDR
  | string;
Swift
@frozen struct Color

Pass a literal, or build one with SwiftUI.Color from import { SwiftUI } from 'swiftui-react-native'.

Type properties

  • 'accentColor'SwiftUI.Color.accentColor

    A color that reflects the accent color of the system or app.

  • 'black'SwiftUI.Color.black

    A black color suitable for use in UI elements.

  • 'blue'SwiftUI.Color.blue

    A context-dependent blue color suitable for use in UI elements.

  • 'brown'SwiftUI.Color.brown

    A context-dependent brown color suitable for use in UI elements.

  • 'clear'SwiftUI.Color.clear

    A clear color suitable for use in UI elements.

  • 'cyan'SwiftUI.Color.cyan

    A context-dependent cyan color suitable for use in UI elements.

  • 'gray'SwiftUI.Color.gray

    A context-dependent gray color suitable for use in UI elements.

  • 'green'SwiftUI.Color.green

    A context-dependent green color suitable for use in UI elements.

  • 'indigo'SwiftUI.Color.indigo

    A context-dependent indigo color suitable for use in UI elements.

  • 'mint'SwiftUI.Color.mint

    A context-dependent mint color suitable for use in UI elements.

  • 'orange'SwiftUI.Color.orange

    A context-dependent orange color suitable for use in UI elements.

  • 'pink'SwiftUI.Color.pink

    A context-dependent pink color suitable for use in UI elements.

  • 'primary'SwiftUI.Color.primary

    The color to use for primary content.

  • 'purple'SwiftUI.Color.purple

    A context-dependent purple color suitable for use in UI elements.

  • 'red'SwiftUI.Color.red

    A context-dependent red color suitable for use in UI elements.

  • 'secondary'SwiftUI.Color.secondary

    The color to use for secondary content.

  • 'teal'SwiftUI.Color.teal

    A context-dependent teal color suitable for use in UI elements.

  • 'white'SwiftUI.Color.white

    A white color suitable for use in UI elements.

  • 'yellow'SwiftUI.Color.yellow

    A context-dependent yellow color suitable for use in UI elements.

Type methods

Overview

You can create a color in one of several ways:

Some view modifiers can take a color as an argument. For example, View.foregroundStyle(_:) uses the color you provide to set the foreground color for view elements, like text or doc://com.apple.documentation/design/human-interface-guidelines/sf-symbols:

Image(systemName: "leaf.fill")
    .foregroundStyle(Color.green)

Because SwiftUI treats colors as View instances, you can also directly add them to a view hierarchy. For example, you can layer a rectangle beneath a sun image using colors defined above:

ZStack {
    skyBlue
    Image(systemName: "sun.max.fill")
        .foregroundStyle(lemonYellow)
}
.frame(width: 200, height: 100)

A color used as a view expands to fill all the space it's given, as defined by the frame of the enclosing ZStack in the above example:

SwiftUI only resolves a color to a concrete value just before using it in a given environment. This enables a context-dependent appearance for system defined colors, or those that you load from an Asset Catalog. For example, a color can have distinct light and dark variants that the system chooses from at render time.

From Apple’s SwiftUI documentation. Code samples there are Swift.

Used by

See also

More in Appearance.