SymbolVariants
A variant of a symbol.
Declaration
type SymbolVariants =
| 'circle'
| 'fill'
| 'none'
| 'rectangle'
| 'slash'
| 'square';struct SymbolVariantsPass a literal, or build one with SwiftUI.SymbolVariants from import { SwiftUI } from 'swiftui-react-native'.
Type properties
'circle'SwiftUI.SymbolVariants.circleA variant that encapsulates the symbol in a circle.
'fill'SwiftUI.SymbolVariants.fillA variant that fills the symbol.
'none'SwiftUI.SymbolVariants.noneNo variant for a symbol.
'rectangle'SwiftUI.SymbolVariants.rectangleA variant that encapsulates the symbol in a rectangle.
'slash'SwiftUI.SymbolVariants.slashA variant that draws a slash through the symbol.
'square'SwiftUI.SymbolVariants.squareA variant that encapsulates the symbol in a square.
Overview
Many of the
doc://com.apple.documentation/design/human-interface-guidelines/sf-symbols
that you can add to your app using an Image or a Label instance
have common variants, like a filled version or a version that's
contained within a circle. The symbol's name indicates the variant:
VStack(alignment: .leading) {
Label("Default", systemImage: "heart")
Label("Fill", systemImage: "heart.fill")
Label("Circle", systemImage: "heart.circle")
Label("Circle Fill", systemImage: "heart.circle.fill")
}You can configure a part of your view hierarchy to use a particular variant
for all symbols in that view and its child views using SymbolVariants.
Add the View.symbolVariant(_:) modifier to a view to set a variant
for that view's environment. For example, you can use the modifier to
create the same set of labels as in the example above, using only the
base name of the symbol in the label declarations:
VStack(alignment: .leading) {
Label("Default", systemImage: "heart")
Label("Fill", systemImage: "heart")
.symbolVariant(.fill)
Label("Circle", systemImage: "heart")
.symbolVariant(.circle)
Label("Circle Fill", systemImage: "heart")
.symbolVariant(.circle.fill)
}Alternatively, you can set the variant in the environment directly by
passing the EnvironmentValues.symbolVariants environment value to the
View.environment(_:_:) modifier:
Label("Fill", systemImage: "heart")
.environment(\.symbolVariants, .fill)SwiftUI sets a variant for you in some environments. For example, SwiftUI
automatically applies the SymbolVariants.fill-swift.type.property
symbol variant for items that appear in the content closure of the
View.swipeActions(edge:allowsFullSwipe:content:)
method, or as the tab bar items of a TabView.
From Apple’s SwiftUI documentation. Code samples there are Swift.
Used by
See also
More in Text and symbols.
- DisabledTextSelectabilityA selectability type that disables text selection by the person using your app.
- EnabledTextSelectabilityA selectability type that enables text selection by the person using your app.
- FindContextThe status of the find navigator for views which support text editing.
- FixedTextVariantThe default text variant preference that chooses the largest available variant.
- FontAn environment-dependent font.
- FontChainFont with chained calls: SwiftUI.Font.bold(...).
- FontContextInformation used to resolve a font.
- FontDesignA design to use for fonts.
- FontLeadingA line spacing adjustment that you can apply to a font.
- FontWeightA weight to use for fonts.
- FontWidthA width to use for fonts that have multiple widths.
- SubmitLabelA semantic label describing the label of submission within a view hierarchy.