HomeiOS Developmentios - How am i able to programmatically change the colour of...

ios – How am i able to programmatically change the colour of sure components in an SVG file utilizing Swift


I’m making a journey app in swiftui the place customers can maintain observe of which international locations they’ve visited. I need to do that by permitting customers to pick out which international locations they’ve visited from an inventory after which show a svg of a world map that fills the visited international locations blue. Right here is an instance: app instance

Under is an instance of the svg file. Each path represents a rustic and has an id. I need to have the ability to discover a path by it is id and alter the colour of it to blue. It is fairly straightforward to do that in javascript however i am having nice bother discovering any documentation on-line for swift.

<path d="m 479.68275,331.6274 -0.077,0.025 -0.258,0.155 -0.147,0.054 -0.134,0.027 -0.105,-0.011 -0.058,-0.091 0.006,-0.139 -0.024,-0.124 -0.02,-0.067 0.038,-0.181 0.086,-0.097 0.119,-0.08 0.188,0.029 0.398,0.116 0.083,0.109 10e-4,0.072 -0.073,0.119 z" title="Andorra" id="AD" />

I’m utilizing SVGKit (https://github.com/SVGKit/SVGKit) to import the svg into my swiftui view. Under is the code that I already must easy show the svg in my opinion.

My SVGImageView struct:

struct SVGImageView: View {
    let svgImage: SVGKImage

    init(svgImage: SVGKImage) {
        self.svgImage = svgImage
    }

    var physique: some View {
        Picture(uiImage: svgImage.uiImage)
            .resizable()
            .scaledToFit()
    }
}

And contained in the swiftui view:

if let svgImage = SVGKImage(named: "world") {
     SVGImageView(svgImage: svgImage)
          .body(width: UIScreen.major.bounds.width * 0.85)
          .padding(.prime)
}

Here’s what this at the moment seems like: my app screenshot

I have not tried something but, i have been totally different repo’s on github however have not had any luck so I made a decision to ask it right here.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments