ShapeStyle
A color or pattern to use when rendering a shape.
Declaration
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;protocol ShapeStyle : SendablePass a literal, or build one with SwiftUI.ShapeStyle from import { SwiftUI } from 'swiftui-react-native'.
Type properties
'background'SwiftUI.ShapeStyle.backgroundThe background style in the current context.
'bar'SwiftUI.ShapeStyle.barA material matching the style of system toolbars.
'black'SwiftUI.ShapeStyle.blackA black color suitable for use in UI elements.
'blue'SwiftUI.ShapeStyle.blueA context-dependent blue color suitable for use in UI elements.
'brown'SwiftUI.ShapeStyle.brownA context-dependent brown color suitable for use in UI elements.
'clear'SwiftUI.ShapeStyle.clearA clear color suitable for use in UI elements.
'cyan'SwiftUI.ShapeStyle.cyanA context-dependent cyan color suitable for use in UI elements.
'fill'SwiftUI.ShapeStyle.fillAn overlay fill style for filling shapes.
'foreground'SwiftUI.ShapeStyle.foregroundThe foreground style in the current context.
'gray'SwiftUI.ShapeStyle.grayA context-dependent gray color suitable for use in UI elements.
'green'SwiftUI.ShapeStyle.greenA context-dependent green color suitable for use in UI elements.
'indigo'SwiftUI.ShapeStyle.indigoA context-dependent indigo color suitable for use in UI elements.
'link'SwiftUI.ShapeStyle.linkA style appropriate for links.
'mint'SwiftUI.ShapeStyle.mintA context-dependent mint color suitable for use in UI elements.
'orange'SwiftUI.ShapeStyle.orangeA context-dependent orange color suitable for use in UI elements.
'pink'SwiftUI.ShapeStyle.pinkA context-dependent pink color suitable for use in UI elements.
'placeholder'SwiftUI.ShapeStyle.placeholderA style appropriate for placeholder text.
'primary'SwiftUI.ShapeStyle.primaryA shape style that maps to the first level of the current content style.
'purple'SwiftUI.ShapeStyle.purpleA context-dependent purple color suitable for use in UI elements.
'quaternary'SwiftUI.ShapeStyle.quaternaryA shape style that maps to the fourth level of the current content style.
'quinary'SwiftUI.ShapeStyle.quinaryA shape style that maps to the fifth level of the current content style.
'red'SwiftUI.ShapeStyle.redA context-dependent red color suitable for use in UI elements.
'regularMaterial'SwiftUI.ShapeStyle.regularMaterialA material that's somewhat translucent.
'secondary'SwiftUI.ShapeStyle.secondaryA shape style that maps to the second level of the current content style.
'selection'SwiftUI.ShapeStyle.selectionA style used to visually indicate selection following platform conventional colors and behaviors.
'separator'SwiftUI.ShapeStyle.separatorA style appropriate for foreground separator or border lines.
'teal'SwiftUI.ShapeStyle.tealA context-dependent teal color suitable for use in UI elements.
'tertiary'SwiftUI.ShapeStyle.tertiaryA shape style that maps to the third level of the current content style.
'thickMaterial'SwiftUI.ShapeStyle.thickMaterialA material that's more opaque than translucent.
'thinMaterial'SwiftUI.ShapeStyle.thinMaterialA material that's more translucent than opaque.
'tint'SwiftUI.ShapeStyle.tintA style that reflects the current tint color.
'ultraThickMaterial'SwiftUI.ShapeStyle.ultraThickMaterialA mostly opaque material.
'ultraThinMaterial'SwiftUI.ShapeStyle.ultraThinMaterialA mostly translucent material.
'white'SwiftUI.ShapeStyle.whiteA white color suitable for use in UI elements.
'windowBackground'SwiftUI.ShapeStyle.windowBackgroundA style appropriate for elements that should match the background of their containing window.
'yellow'SwiftUI.ShapeStyle.yellowA 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:
- 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))
- Tracing the outline of a shape with a style with either the
Shape.stroke(_:lineWidth:)or theShape.stroke(_:style:)modifier:
RoundedRectangle(cornerRadius: 10) .stroke(.mint, lineWidth: 10) .frame(width: 200, height: 50)
- 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) }
From Apple’s SwiftUI documentation. Code samples there are Swift.
Used by
- DocumentLaunchViewA view to present when launching document-related user experience.
- backgroundSets the view's background to a style.
- backgroundStyleSets the specified style to render backgrounds within the view.
- borderAdds a border to this view with the specified style and width.
- containerBackgroundSets the container background of the enclosing container using a view.
- foregroundStyleSets the primary, secondary, and tertiary levels of the foreground style.
- strokeBorderReturns a view that is the result of filling the lineWidth-sized border (aka inner stroke) of self with content. This is equivalent to insetting self by lineWidth / 2 and stroking the resulting shape with lineWidth as the line-width.
- overlayLayers the specified style in front of this view.
- presentationBackgroundSets the presentation background of the enclosing sheet using a shape style.
- fillFills this shape with a color or gradient.
- strokeTraces the outline of this shape with a color or gradient.
- fillFills this shape with a color or gradient.
- strokeTraces the outline of this shape with a color or gradient.
- strokeBorderReturns a view that's the result of filling an inner stroke of this view with the content you supply.
- foregroundStyleSets the style of the text displayed by this view.
- tintSets the tint color within this view.
- toolbarBackgroundSpecifies the preferred shape style of the background of a bar managed by SwiftUI.
See also
More in Styles.
- AccessoryCircularCapacityGaugeStyleA gauge style that displays a closed ring that's partially filled in to indicate the gauge's current value.
- AccessoryCircularGaugeStyleA gauge style that displays an open ring with a marker that appears at a point along the ring to indicate the gauge's current value.
- AccessoryLinearCapacityGaugeStyleA gauge style that displays bar that fills from leading to trailing edges as the gauge's current value increases.
- AccessoryLinearGaugeStyleA gauge style that displays bar with a marker that appears at a point along the bar to indicate the gauge's current value.
- ArrangementViewStyleA style that configures an ArrangementView with an arrangement.
- AutomaticArrangementViewStyleThe default arrangement view style.
- AutomaticControlGroupStyleThe default control group style.
- AutomaticDisclosureGroupStyleA disclosure group style that resolves its appearance automatically based on the current context.
- AutomaticFormStyleThe default form style.
- AutomaticLabeledContentStyleThe default labeled content style.
- AutomaticNavigationSplitViewStyleA navigation split style that resolves its appearance automatically based on the current context.
- AutomaticTableStyleThe default table style in the current context.