In SwiftUI, how does renderingMode(_:) differ from symbolRenderingMode(_:), and when do you use monochrome, hierarchical, palette or multicolor?
answer
- any image versus symbols only
- shape only or own pixels
- layers of a symbol
- one colour at several opacities
- two or three foreground styles
basics
~10 srenderingMode(:) works on any Image and chooses template (shape filled with the foreground style) or original (own pixels). symbolRenderingMode(:) works on SF Symbols' layers: monochrome, hierarchical, palette or multicolor.
solid answer
~40 s`renderingMode(_:)` is an `Image` method from iOS 13 with two values: `.template` draws only the image's shape filled with the current foreground style, `.original` draws its own pixels. It is how you tint a one-colour icon asset. `symbolRenderingMode(_:)`, from iOS 15, applies only to SF Symbols and decides how a symbol's layers are coloured: `.monochrome` paints every layer in one style; `.hierarchical` uses one style at decreasing opacity for secondary and tertiary layers; `.palette` takes a separate style per layer from `foregroundStyle(_:_:)` or `foregroundStyle(_:_:_:)`; `.multicolor` uses the colours the symbol defines, such as a yellow sun over a white cloud. As a view modifier it sets the environment for every symbol in the subtree. Variants such as `.fill` are a separate axis, set by `symbolVariant(_:)`.
code
swift · 29 linesimport SwiftUI
struct RatingRow: View {
let rating: Int
let isFavourite: Bool
var body: some View {
HStack {
ForEach(1...5, id: \.self) { star in
Image(systemName: star <= rating ? "star.fill" : "star")
.foregroundStyle(.yellow)
}
Image(systemName: "heart")
.symbolVariant(isFavourite ? .fill : .none)
.symbolRenderingMode(.palette)
.foregroundStyle(.red, .pink)
Image(systemName: "cloud.sun.rain.fill")
.symbolRenderingMode(.multicolor)
Image(systemName: "flame.fill")
.symbolRenderingMode(.hierarchical)
.foregroundStyle(.orange)
Image("chef-hat")
.renderingMode(.template)
.foregroundStyle(.tint)
}
.font(.title3)
.imageScale(.large)
}
}go deeper
Recall that symbols are templates tinted by foregroundStyle, and that renderingMode(.template) tints a one-colour asset.
Explain the four symbol rendering modes and which colours each draws, and keep variants separate from modes.
Set modes and variants on containers through the environment, and know where SwiftUI applies the fill variant for you.
Agree an icon colour rule with design, such as hierarchical in brand colour by default and multicolor only where colour carries meaning, so screens stay consistent.
## Two modifiers that sound alike A recipe app colours many icons: gold rating stars, a red favourite heart, a weather badge for a picnic recipe and a chef-hat logo from the asset catalog. Two SwiftUI APIs control this, and they work at different levels: - **`renderingMode(_:)`** is a method on `Image`, available since iOS 13, taking `Image.TemplateRenderingMode`: `.template` or `.original`. It applies to any image: asset, symbol or one built from a `UIImage`. - **`symbolRenderingMode(_:)`**, available since iOS 15, takes a `SymbolRenderingMode` and applies only to symbol images. It exists both as an `Image` method and as a view modifier that writes the `symbolRenderingMode` environment value, so it reaches every symbol inside a container. ## Template versus original A **template** rendering uses only the image's shape, its alpha channel, and fills that shape with the current foreground style. An **original** rendering draws the image's own colours. A bitmap asset draws as original by default; SF Symbols draw as templates, which is why `foregroundStyle(.yellow)` turns a star gold. To tint a single-colour icon such as the chef hat, set Render As to Template Image in the asset catalog, or call `.renderingMode(.template)` in code and then `.foregroundStyle(.tint)`. Applying `.template` to a full-colour photo turns it into a flat silhouette, because its colours are discarded. Template rendering is also what makes icons adapt to appearance. A template icon filled with `.primary` or the app's tint follows light and dark mode and a changed accent colour automatically, while a black original PNG stays black on a dark background. That is the practical reason teams ship single-colour icons as templates rather than as several coloured copies. ## Where to set them `renderingMode(_:)` exists only as an `Image` method, so it sits on each image, directly after the initialiser and before any view modifier. `symbolRenderingMode(_:)` exists both on `Image` and as a view modifier; the view modifier writes the `symbolRenderingMode` environment value, so one call on a container reaches every symbol inside it, the same way `font(_:)` reaches every `Text`. ## The four symbol rendering modes Many SF Symbols are drawn in layers: the heart and the circle in `heart.circle`, the cloud, sun and rain in `cloud.sun.rain.fill`. The mode decides how those layers are coloured. | Mode | Colours used | Typical use | |---|---|---| | `.monochrome` | one foreground style on every layer | toolbar icons, inline glyphs | | `.hierarchical` | one style, lower opacity on secondary and tertiary layers | depth from a single brand colour | | `.palette` | a separate style per layer, from `foregroundStyle(_:_:)` or `foregroundStyle(_:_:_:)` | a red heart on a pink circle | | `.multicolor` | the colours the symbol itself defines | weather, battery, status symbols | A few practical rules follow: 1. Choose **hierarchical** when you want depth but only own one colour; it keeps the icon on-brand without a palette. 2. Choose **palette** when design specifies exact colours per layer, and pass as many styles to `foregroundStyle` as the symbol has layers that matter. 3. Choose **multicolor** for symbols whose colours carry meaning, such as weather; the SF Symbols app shows which symbols ship a multicolour version. 4. Set the mode once on a container, such as a `VStack` of rating rows, rather than on each image. ## Variants are a different axis A symbol's **variant** decides which glyph is drawn, not how it is coloured. `symbolVariant(_:)` takes `SymbolVariants` values such as `.fill`, `.circle`, `.square`, `.slash` and `.none` and writes them to the environment: - `Image(systemName: "heart").symbolVariant(.fill)` draws `heart.fill`. - Variants accumulate when applied more than once, and when two shape variants conflict, the one closest to the symbol wins. - A symbol without the requested variant, such as `list.bullet` with `.fill`, is drawn unchanged. - SwiftUI applies `.fill` for you in some places, such as swipe-action content and tab bar items; `.environment(\.symbolVariants, .none)` opts a symbol out. ## Common mistakes - Expecting `symbolRenderingMode(.multicolor)` to colour a bitmap asset: it affects symbol images only. - Expecting `.palette` to choose colours by itself; it takes them from the styles you pass to `foregroundStyle`. - Switching between `heart` and `heart.fill` strings by hand when one `symbolVariant` on a container would do it for every icon. - Tinting a full-colour photo with `.template`, which removes its colours entirely. ## Summary Rendering mode is about **any image**: shape or own pixels. Symbol rendering mode is about **a symbol's layers**: one colour, one colour in depth, several colours or the symbol's own. Variant is about **which glyph**. Keeping the three apart is what interviewers check.
- How do you make every symbol in a recipe card's action row filled without changing each symbol name?Apply `.symbolVariant(.fill)` to the row's container. It sets the `symbolVariants` environment value, so `heart`, `bookmark` and `square.and.arrow.up` inside draw their filled versions where one exists; a symbol with no filled version draws unchanged. A single image opts out with `.environment(\.symbolVariants, .none)`.
- Should a one-colour icon asset be made a template in the asset catalog or in code?Setting Render As to Template Image in the asset catalog makes the asset a template wherever it is used, so it tints with the foreground style by default. `renderingMode(_:)` in code decides per use site and suits an asset that is a template in one place and full colour in another. For icons that are always tinted, the catalog setting keeps call sites short.
- symbolRenderingMode(.multicolor) adds colour to any image, including bitmap assets.
- renderingMode(.template) is only for SF Symbols.
- Hierarchical mode needs a separate colour for each layer.
- symbolVariant(.fill) changes how a symbol is coloured rather than which glyph is drawn.
- Palette mode picks its layer colours automatically from the symbol's design.