One Logo Pool Ball
SwiftUICore · IOS API REFERENCE

ShapeStyle

protocol · iOS 13.0+ · SDK 27.1

protocol ShapeStyle : Sendable

A color or pattern to use when rendering a shape. 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: * Filling a shape with a style with the ``Shape/fill(_:style:)`` modifier: ``` 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)) ``` ![A screenshot of a quarter of a circle filled with a radial gradient.](ShapeStyle-1) * Tracing the outline of a shape with a style with either the ``Shape/stroke(_:lineWidth:)`` or the ``Shape/stroke(_:style:)`` modifier: ``` RoundedRectangle(cornerRadius: 10) .stroke(.mint, lineWidth: 10) .frame(width: 200, height: 50) ``` ![A screenshot of a rounded rectangle, outlined in mint.](ShapeStyle-2) * Styling the foreground elements in a view with the ``View/foregroundStyle(_:)`` modifier: ``` VStack(alignment: .leading) { Text("Primary") .font(.title) Text("Secondary") .font(.caption) .foregroundStyle(.secondary) } ``` ![A screenshot of a title in the primary content color above a subtitle in the secondary content color.](ShapeStyle-3)

Members (1)

method · iOS 17.0+

resolve

Swift declaration
func resolve(in environment: EnvironmentValues) -> Never

Skipped declarations

66 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.

ShapeStyle.linearGradient(_:startPoint:endPoint:)

Static protocol requirements cannot be called through an instance.

ShapeStyle.linearGradient(colors:startPoint:endPoint:)

Static protocol requirements cannot be called through an instance.

ShapeStyle.linearGradient(stops:startPoint:endPoint:)

Static protocol requirements cannot be called through an instance.

ShapeStyle.radialGradient(_:center:startRadius:endRadius:)

Static protocol requirements cannot be called through an instance.

ShapeStyle.radialGradient(colors:center:startRadius:endRadius:)

Static protocol requirements cannot be called through an instance.

ShapeStyle.radialGradient(stops:center:startRadius:endRadius:)

Static protocol requirements cannot be called through an instance.

ShapeStyle.ellipticalGradient(_:center:startRadiusFraction:endRadiusFraction:)

Static protocol requirements cannot be called through an instance.

ShapeStyle.ellipticalGradient(colors:center:startRadiusFraction:endRadiusFraction:)

Static protocol requirements cannot be called through an instance.

ShapeStyle.ellipticalGradient(stops:center:startRadiusFraction:endRadiusFraction:)

Static protocol requirements cannot be called through an instance.

ShapeStyle.angularGradient(_:center:startAngle:endAngle:)

Static protocol requirements cannot be called through an instance.

ShapeStyle.angularGradient(colors:center:startAngle:endAngle:)

Static protocol requirements cannot be called through an instance.

ShapeStyle.angularGradient(stops:center:startAngle:endAngle:)

Static protocol requirements cannot be called through an instance.

ShapeStyle.conicGradient(_:center:angle:)

Static protocol requirements cannot be called through an instance.

ShapeStyle.conicGradient(colors:center:angle:)

Static protocol requirements cannot be called through an instance.

ShapeStyle.conicGradient(stops:center:angle:)

Static protocol requirements cannot be called through an instance.

ShapeStyle.linearGradient(_:startPoint:endPoint:)

This protocol needs associated types that cannot yet cross the bridge.

ShapeStyle.radialGradient(_:center:startRadius:endRadius:)

This protocol needs associated types that cannot yet cross the bridge.

ShapeStyle.ellipticalGradient(_:center:startRadiusFraction:endRadiusFraction:)

This protocol needs associated types that cannot yet cross the bridge.

ShapeStyle.angularGradient(_:center:startAngle:endAngle:)

This protocol needs associated types that cannot yet cross the bridge.

ShapeStyle.conicGradient(_:center:angle:)

This protocol needs associated types that cannot yet cross the bridge.

ShapeStyle.image(_:sourceRect:scale:)

Static protocol requirements cannot be called through an instance.

ShapeStyle.fill

Static protocol requirements cannot be called through an instance.

ShapeStyle.opacity(_:)

This protocol needs associated types that cannot yet cross the bridge.

ShapeStyle.opacity(_:)

This protocol needs associated types that cannot yet cross the bridge.

ShapeStyle.blendMode(_:)

This protocol needs associated types that cannot yet cross the bridge.

ShapeStyle.blendMode(_:)

This protocol needs associated types that cannot yet cross the bridge.

ShapeStyle.regularMaterial

Static protocol requirements cannot be called through an instance.

ShapeStyle.thickMaterial

Static protocol requirements cannot be called through an instance.

ShapeStyle.thinMaterial

Static protocol requirements cannot be called through an instance.

ShapeStyle.ultraThinMaterial

Static protocol requirements cannot be called through an instance.

All SwiftUICore types →