alwaysTemplate
AlwaysTemplate is a rendering mode used in UIKit to treat an image as a template image. When an image is rendered in a view that supports tintColor, such as UIImageView, UIButton, or UIBarButtonItem, the non-transparent areas of the image are used as a mask and are drawn with the view’s tintColor rather than the image’s original colors. This enables consistent theming and icon coloring across an app.
Conceptually, a template image preserves only its alpha mask. The actual color comes from the tintColor applied
Usage in code typically involves creating or converting an image to template rendering mode, assigning it to
let icon = UIImage(named: "icon")?.withRenderingMode(.alwaysTemplate)
imageView.tintColor = .systemBlue
In Interface Builder, you can set the image’s Rendering to Template Image and adjust the view’s Tint
Notes and limitations: alwaysTemplate is appropriate for monochrome icons. If the source image contains multiple colors,