Declaration
compose().symbolVariant(variant: SwiftUI.SymbolVariants)nonisolated func symbolVariant(_ variant: SymbolVariants) -> some ViewParameters
variant*SwiftUI.SymbolVariantsThe variant to use for symbols. Use the values in
SymbolVariants.
Return value
A view that applies the specified symbol variant or variants to itself and its child views.
Discussion
When you want all the
doc://com.apple.documentation/design/human-interface-guidelines/sf-symbols
in a part of your app's user interface to use the same variant, use the
symbolVariant(_:) modifier with a SymbolVariants value, like
SymbolVariants.fill-swift.type.property:
VStack(spacing: 20) {
HStack(spacing: 20) {
Image(systemName: "person")
Image(systemName: "folder")
Image(systemName: "gearshape")
Image(systemName: "list.bullet")
}
HStack(spacing: 20) {
Image(systemName: "person")
Image(systemName: "folder")
Image(systemName: "gearshape")
Image(systemName: "list.bullet")
}
.symbolVariant(.fill) // Shows filled variants, when available.
}A symbol that doesn't have the specified variant remains unaffected.
In the example above, the list.bullet symbol doesn't have a filled
variant, so the symbolVariant(_:) modifer has no effect.
If you apply the modifier more than once, its effects accumulate. Alternatively, you can apply multiple variants in one call:
Label("Airplane", systemImage: "airplane.circle.fill")
Label("Airplane", systemImage: "airplane")
.symbolVariant(.circle)
.symbolVariant(.fill)
Label("Airplane", systemImage: "airplane")
.symbolVariant(.circle.fill)All of the labels in the code above produce the same output:
You can apply all these variants in any order, but
if you apply more than one shape variant, the one closest to the
symbol takes precedence. For example, the following image uses the
SymbolVariants.square-swift.type.property shape:
Image(systemName: "arrow.left")
.symbolVariant(.square) // This shape takes precedence.
.symbolVariant(.circle)
.symbolVariant(.fill)To cause a symbol to ignore the variants currently in the environment,
directly set the EnvironmentValues.symbolVariants environment value
to SymbolVariants.none using the View.environment(_:_:) modifer.
See also
More in Text and symbols.
- allowsTighteningSets whether text in this view can compress the space between characters when necessary to fit text in a line.
- autocorrectionDisabledSets whether to disable autocorrection for this view.
- baselineOffsetSets the vertical offset for the text relative to its baseline in this view.
- boldApplies a bold font weight to the text in this view.
- findDisabledPrevents find and replace operations in a text editor.
- findNavigatorProgrammatically presents the find and replace interface for text editor views.
- fontSets the default font for text in this view.
- fontDesignSets the font design of the text in this view.
- fontWeightSets the font weight of the text in this view.
- fontWidthSets the font width of the text in this view.
- interactionActivityTrackingTagSets a tag that you use for tracking interactivity.
- italicApplies italics to the text in this view.