Declaration
compose().renderingMode(
renderingMode: SwiftUI.ImageTemplateRenderingMode | null
)func renderingMode(
_ renderingMode: Image.TemplateRenderingMode?
) -> ImageParameters
renderingMode*SwiftUI.ImageTemplateRenderingMode | nullThe mode SwiftUI uses to render images.
Return value
A modified Image.
Discussion
The TemplateRenderingMode enumeration has two cases:
TemplateRenderingMode.original and TemplateRenderingMode.template.
The original mode renders pixels as they appear in the original source
image. Template mode renders all nontransparent pixels as the
foreground color, which you can use for purposes like creating image
masks.
The following example shows both rendering modes, as applied to an icon image of a green circle with darker green border:
Image("dot_green")
.renderingMode(.original)
Image("dot_green")
.renderingMode(.template)You also use renderingMode to produce multicolored system graphics
from the SF Symbols set. Use the TemplateRenderingMode.original
mode to apply a foreground color to all parts of the symbol except
those that have a distinct color in the graphic. The following
example shows three uses of the person.crop.circle.badge.plus symbol
to achieve different effects:
- A default appearance with no foreground color or template rendering mode specified. The symbol appears all black in light mode, and all white in Dark Mode.
- The multicolor behavior achieved by using
originaltemplate rendering mode, along with a blue foreground color. This mode causes the graphic to override the foreground color for distinctive parts of the image, in this case the plus icon. - A single-color template behavior achieved by using
templaterendering mode with a blue foreground color. This mode applies the foreground color to the entire image, regardless of the user's Appearance preferences.
HStack {
Image(systemName: "person.crop.circle.badge.plus")
Image(systemName: "person.crop.circle.badge.plus")
.renderingMode(.original)
.foregroundColor(.blue)
Image(systemName: "person.crop.circle.badge.plus")
.renderingMode(.template)
.foregroundColor(.blue)
}
.font(.largeTitle)Use the SF Symbols app to find system images that offer the multicolor feature. Keep in mind that some multicolor symbols use both the foreground and accent colors.
See also
More in Image modifiers.
- allowedDynamicRangeReturns a new image configured with the specified allowed dynamic range.
- antialiasedSpecifies whether SwiftUI applies antialiasing when rendering the image. allow antialiasing. Pass true to allow antialising, false otherwise.
- interpolationSpecifies the current level of quality for rendering an image that requires interpolation.
- resizableSets the mode by which SwiftUI resizes an image to fit its space.
- symbolColorRenderingModeSets the color rendering mode of the image.
- symbolRenderingModeSets the rendering mode for symbol images within this view.
- symbolVariableValueModeSets the variable value mode mode for symbol images within this view.