EDIT My answer ignores the aspect that you explicitly want SVG
images, sorry for that; still, you could convert your images to PDF
and use the described approach.
You can use use the renderingMode
property of UIImage
to generate a template image which supports setting a tint color. This will interpret all non-transparent pixels as the "foreground" which will get colored by the tint.
There are two ways to do so:
- Set the image's render mode in the asset catalog by opening the Attributes Inspector and setting the dropdown
Render as
to Template Image
. When you load this image with UIImage(named:)
you automatically get it as a template image.
- When you already have the
UIImage
instance you can convert it to a template image: let templateImage = image.withRenderingMode(.alwaysTemplate)
In both cases you can set the tint color of the image with templateImage.tintColor = yourColor
.