ShapeStyle

A color or pattern to use when rendering a shape.

ProtocoliOS 13.0+macOS 10.15+tvOS 13.0+watchOS 6.0+ShapeStyle in SwiftUI

Declaration

React
type ShapeStyle =
  | 'background'
  | 'bar'
  | 'black'
  | 'blue'
  | 'brown'
  | 'clear'
  | 'cyan'
  | 'fill'
  | 'foreground'
  | 'gray'
  | 'green'
  | 'indigo'
  | 'link'
  | 'mint'
  | 'orange'
  | 'pink'
  | 'placeholder'
  | 'primary'
  | 'purple'
  | 'quaternary'
  | 'quinary'
  | 'red'
  | 'regularMaterial'
  | 'secondary'
  | 'selection'
  | 'separator'
  | 'teal'
  | 'tertiary'
  | 'thickMaterial'
  | 'thinMaterial'
  | 'tint'
  | 'ultraThickMaterial'
  | 'ultraThinMaterial'
  | 'white'
  | 'windowBackground'
  | 'yellow'
  | { angularGradient: { colors: Color[]; center: UnitPoint; startAngle: Angle; endAngle: Angle; }; }
  | { angularGradient: { gradient: Gradient; center: UnitPoint; startAngle: Angle; endAngle: Angle; }; }
  | { angularGradient: { stops: GradientStop[]; center: UnitPoint; startAngle: Angle; endAngle: Angle; }; }
  | { blendMode: BlendMode; }
  | { conicGradient: { colors: Color[]; center: UnitPoint; angle?: Angle; }; }
  | { conicGradient: { gradient: Gradient; center: UnitPoint; angle?: Angle; }; }
  | { conicGradient: { stops: GradientStop[]; center: UnitPoint; angle?: Angle; }; }
  | { ellipticalGradient: { colors: Color[]; center?: UnitPoint; startRadiusFraction?: number; endRadiusFraction?: number; }; }
  | { ellipticalGradient: { gradient: Gradient; center?: UnitPoint; startRadiusFraction?: number; endRadiusFraction?: number; }; }
  | { ellipticalGradient: { stops: GradientStop[]; center?: UnitPoint; startRadiusFraction?: number; endRadiusFraction?: number; }; }
  | { image: { image: Image; sourceRect?: CGRect; scale?: number; }; }
  | { linearGradient: { colors: Color[]; startPoint: UnitPoint; endPoint: UnitPoint; }; }
  | { linearGradient: { gradient: Gradient; startPoint: UnitPoint; endPoint: UnitPoint; }; }
  | { linearGradient: { stops: GradientStop[]; startPoint: UnitPoint; endPoint: UnitPoint; }; }
  | { opacity: number; }
  | { radialGradient: { colors: Color[]; center: UnitPoint; startRadius: number; endRadius: number; }; }
  | { radialGradient: { gradient: Gradient; center: UnitPoint; startRadius: number; endRadius: number; }; }
  | { radialGradient: { stops: GradientStop[]; center: UnitPoint; startRadius: number; endRadius: number; }; }
  | { shadow: ShadowStyle; }
  | AngularGradient
  | AnyGradient
  | BackgroundStyle
  | Color
  | ColorResolved
  | ColorResolvedHDR
  | EllipticalGradient
  | FillShapeStyle
  | ForegroundStyle
  | Gradient
  | HierarchicalShapeStyle
  | ImagePaint
  | LinearGradient
  | LinkShapeStyle
  | Material
  | MeshGradient
  | PlaceholderTextShapeStyle
  | RadialGradient
  | SelectionShapeStyle
  | SeparatorShapeStyle
  | Shader
  | ShapeStyleChain
  | TintShapeStyle
  | WindowBackgroundShapeStyle;
Swift
protocol ShapeStyle : Sendable

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

Type properties

  • 'background'SwiftUI.ShapeStyle.background

    The background style in the current context.

  • A material matching the style of system toolbars.

  • 'black'SwiftUI.ShapeStyle.black

    A black color suitable for use in UI elements.

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

  • 'brown'SwiftUI.ShapeStyle.brown

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

  • 'clear'SwiftUI.ShapeStyle.clear

    A clear color suitable for use in UI elements.

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

  • An overlay fill style for filling shapes.

  • 'foreground'SwiftUI.ShapeStyle.foreground

    The foreground style in the current context.

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

  • 'green'SwiftUI.ShapeStyle.green

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

  • 'indigo'SwiftUI.ShapeStyle.indigo

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

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

  • 'orange'SwiftUI.ShapeStyle.orange

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

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

  • 'placeholder'SwiftUI.ShapeStyle.placeholder

    A style appropriate for placeholder text.

  • 'primary'SwiftUI.ShapeStyle.primary

    A shape style that maps to the first level of the current content style.

  • 'purple'SwiftUI.ShapeStyle.purple

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

  • 'quaternary'SwiftUI.ShapeStyle.quaternary

    A shape style that maps to the fourth level of the current content style.

  • 'quinary'SwiftUI.ShapeStyle.quinary

    A shape style that maps to the fifth level of the current content style.

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

  • 'regularMaterial'SwiftUI.ShapeStyle.regularMaterial

    A material that's somewhat translucent.

  • 'secondary'SwiftUI.ShapeStyle.secondary

    A shape style that maps to the second level of the current content style.

  • 'selection'SwiftUI.ShapeStyle.selection

    A style used to visually indicate selection following platform conventional colors and behaviors.

  • 'separator'SwiftUI.ShapeStyle.separator

    A style appropriate for foreground separator or border lines.

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

  • 'tertiary'SwiftUI.ShapeStyle.tertiary

    A shape style that maps to the third level of the current content style.

  • 'thickMaterial'SwiftUI.ShapeStyle.thickMaterial

    A material that's more opaque than translucent.

  • 'thinMaterial'SwiftUI.ShapeStyle.thinMaterial

    A material that's more translucent than opaque.

  • A style that reflects the current tint color.

  • 'ultraThickMaterial'SwiftUI.ShapeStyle.ultraThickMaterial

    A mostly opaque material.

  • 'ultraThinMaterial'SwiftUI.ShapeStyle.ultraThinMaterial

    A mostly translucent material.

  • 'white'SwiftUI.ShapeStyle.white

    A white color suitable for use in UI elements.

  • 'windowBackground'SwiftUI.ShapeStyle.windowBackground

    A style appropriate for elements that should match the background of their containing window.

  • 'yellow'SwiftUI.ShapeStyle.yellow

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

Type methods

Overview

You create custom shape styles by declaring a type that conforms to the ShapeStyle protocol and implementing the required resolve function to return a shape style that represents the desired appearance based on the current environment.

For example this shape style reads the current color scheme from the environment to choose the blend mode its color will be composited with:

struct MyShapeStyle: ShapeStyle {
    func resolve(in environment: EnvironmentValues) -> some ShapeStyle {
        if environment.colorScheme == .light {
            return Color.red.blendMode(.lighten)
        } else {
            return Color.red.blendMode(.darken)
        }
    }
}

In addition to creating a custom shape style, you can also use one of the concrete styles that SwiftUI defines. To indicate a specific color or pattern, you can use Color or the style returned by ShapeStyle.image(_:sourceRect:scale:), or one of the gradient types, like the one returned by ShapeStyle.radialGradient(_:center:startRadius:endRadius:). To set a color that's appropriate for a given context on a given platform, use one of the semantic styles, like ShapeStyle.background or ShapeStyle.primary.

You can use a shape style by:

Path { path in path.move(to: .zero) path.addLine(to: CGPoint(x: 50, y: 0)) path.addArc( center: .zero, radius: 50, startAngle: .zero, endAngle: .degrees(90), clockwise: false) } .fill(.radialGradient( Gradient(colors: [.yellow, .red]), center: .topLeading, startRadius: 15, endRadius: 80))

RoundedRectangle(cornerRadius: 10) .stroke(.mint, lineWidth: 10) .frame(width: 200, height: 50)

VStack(alignment: .leading) { Text("Primary") .font(.title) Text("Secondary") .font(.caption) .foregroundStyle(.secondary) }

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

Used by

See also

More in Styles.