exyte / SVGView

SVG parser and renderer written in SwiftUI
MIT License
664 stars 80 forks source link

Question: How to apply tint to SVGView? #59

Open NikSrg opened 10 months ago

NikSrg commented 10 months ago

Hi. I just started to use SVGView. I need to apply a tint to the svg image. How can I?

I tried unseccessfully:

SVGView(data: data)
                .foregroundColor(.blue)

SVGView(data: data)
                .tint(.blue)

SVGView(data: data)
                .background(Color.blue)

Thanks for any advice.

Zulqurnain24 commented 10 months ago

I have same question as facing the same problem

petterobam commented 9 months ago

+1, me too.

missingems commented 3 days ago

A bit unintuitive, but I have found a way to apply a "tint" color by masking your SVG on a color. This is also more performant than setting the fill color to every shape via a loop imperatively.

@Zulqurnain24 @petterobam @NikSrg tagging y'all in case you still looking for a solution.

ZStack {
  if let imageData {
    tintColor.mask {
      SVGView(data: imageData)
    }
  }
}