How to color .svg images in SwiftUI

José Guerra
2 min readMar 28, 2024

--

Well, this took me like 3 hours to figure it out, and there’s no much information on the internet. So I prepare this short guide to accomplish this, that seriously is extremely easy and I almost create the wheel trying to do this.

Let’s start including an .svg image in the assets folder, and assign it a name.

We’ll get something like this.

Now this is the most important, change “Render As” from Default to Template Image.

With this change done, now you’ll be able to change the color using .foregroundColor() or .foregroundStyle().

I know this is pretty basic, but I was downloading packages, struggling with chatGPT trying to embed a package in UIKit into my SwiftUI project until I found a reddit answer with a link to a strange website with no css and there it had my answer.

Thanks for reading, maybe I’ll be uploading more of this short guides with things I can’t find easily so you don’t have to waste your time too.

--

--