Contents

SymbolVariants

A variant of a symbol.

Declaration

struct SymbolVariants

Overview

Many of the 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")
}

[Image]

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 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 symbolVariants environment value to the environment(_:_:) modifier:

Label("Fill", systemImage: "heart")
    .environment(\.symbolVariants, .fill)

SwiftUI sets a variant for you in some environments. For example, SwiftUI automatically applies the fill symbol variant for items that appear in the content closure of the swipeActions(edge:allowsFullSwipe:content:) method, or as the tab bar items of a TabView.

Topics

Getting symbol variants

Modifying a variant

Comparing variants

See Also

Setting a symbol variant