GenerallyHelpfulSoftware / SVGgh

A framework for using SVG artwork in iOS Apps. Includes a UIView and a button class, printing and PDF export.
MIT License
141 stars 38 forks source link

Change tint color of SVG #24

Closed haashem closed 8 years ago

haashem commented 8 years ago

how can I change tint color of my SVG file? I load the render to an SVGRenderLayer.

let svgRender = SVGRenderer(contentsOfURL: NSURL(string: "http://static.foodiran.com/resource/app/nayeb/cat/1412.svg")!)
            svgRender.setCurrentColor(UIColor.greenColor())
            let svgLayer = SVGRendererLayer()
            svgLayer.bounds = svgRender.viewRect;
            svgLayer.backgroundColor = UIColor.cyanColor().CGColor
            svgLayer.defaultColor = UIColor.greenColor()
            svgRender.setCurrentColor(UIColor.greenColor())
            svgLayer.renderer = svgRender
            self.vectorView.layer.addSublayer(svgLayer)
            svgLayer.position = CGPointMake(self.vectorView.width/2, self.vectorView.height/2.0)
grhowes commented 8 years ago

First of all, you have to mark the SVG to use a current color instead of a hard coded color. So <path fill="#020202" becomes <path fill="currentColor"

Also, I should say that I've never tested the library against remote URLs.

haashem commented 8 years ago

what a trick! mention it in README thanks for quick answer!

grhowes commented 8 years ago

Again I'd highly recommend against using the renderer in this way, as it will make synchronous network calls. I'd download the file locally and then set up the renderer.