Structure

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")
}

A screenshot showing an outlined heart, a filled heart, a heart in

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

Default Implementations 省略時実装

Relationships 関係

Conforms To 次に準拠

See Also 参照

Symbol Appearance