SymbolVariants

A variant of a symbol.

StructureiOS 15.0+macOS 12.0+tvOS 15.0+watchOS 8.0+SymbolVariants in SwiftUI

Declaration

React
type SymbolVariants =
  | 'circle'
  | 'fill'
  | 'none'
  | 'rectangle'
  | 'slash'
  | 'square';
Swift
struct SymbolVariants

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

Type properties

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.