SF Symbols

Overview

SF Symbols is a macOS app from Apple that provides over 5,000 icons. These can be rendered in custom app using the Image view with the systemName argument.

Rendering Modes

Some symbols support multiple symbol rendering modes that enable using different colors for parts of the icon. To see the available rendering modes for a given icon, select the icon and click the paint brush tab in the Inspector on the right. Each icon has a preferred rendering mode, but a different rendering mode can be selected by applying the renderingMode view modifier.

To specify a symbol rendering mode, apply the symbolRenderingMode. The supported symbol rendering modes include:

When the symbol rendering mode is not specified, the preferred rendering mode of the icon of is used.

Variable Colors

Icons that support variable colors are grouped in the "Variable" category. These display additional parts of the icon as a percentage value increases. To see this in action:

Here's an example of using such an icon:

// The @State property wrapper is described later.
// It allows a view instance to maintain state inside the property wrapper.
@State private var percent = 0.0
...
Image(systemName: "cellularbars", variableValue: percent)
Button("Decrease") {
if percent > 0 { percent -= 0.1 }
}
Button("Increase") {
if percent < 1 { percent += 0.1 }
}

See the SFSymbolsDemo app in GitHub.

Template Mode

To ignore the colors in a multicolor SF Symbol icon and just use it as a template for applying a single specified color, apply the renderingMode view modifier with the argument value .template. For example:

Image(systemName: "doc.fill.badge.plus")
.renderingMode(.template)
.resizable()
.foregroundColor(.pink)
.scaledToFit()
.frame(width: 100, height: 100)

Animation

iOS 17 added the ability to animate SF Symbols. See the folloing WWDC 2023 sessions:

SF Symbols 5 added an Animation Inspector, shown in the screenshot below. This provides a way to see all the animation options available for a given SF Symbol and preview them without writing any code. To copy Swift code for a specified animation, click the clipboard icon and select "Copy Configuration for Swift".

SF Symbols Animation Inspector

There are four animation behaviors:

SF Symbols are composed of layers can be individually animated. By default the layers animate one at a time, but they can be configured to animate at the same time.

Many SF Symbols define multiple layers. Animation presets can be applied to all or specific layers of any SF Symbol. The presets include:

To add an effect to an SF Symbol, apply the symbolEffect view modifier, passing it an enum value that specifies the effect. Effects can be configured by chaining values. For example, .symbolEffect(.variableColor.iterative.reversing).

To combine effects, apply the symbolEffect view modifier multiple times. For example:

Image(systemName: "wifi.router")
.symbolEffect(.variableColor.iterative.reversing)`.
.symbolEffect(.scale.up)`.

To cause an effect to stop when a boolean value becomes false, add the isActive argument. For example:

@State private var isActive = false
let size = 100.0

Image(systemName: "ifi")
// .imageScale(.large)
.resizable()
.scaledToFit()
.frame(width: size, height: size)
.foregroundStyle(.tint)
.symbolEffect(
.pulse,
options: .speed(2),
isActive: isActive
)

The symbolEffect view modifier can be applied to a parent view such as an HStack or VStack in order to apply it to all SF Symbols inside. To remove the effect from a specific Image view inside the parent view, apply the symbolEffectsRemoved view modifier.