mchoe / SwiftSVG

A simple, performant, and lightweight SVG parser
Other
1.93k stars 230 forks source link

Center SVG #60

Open toonvanstrijp opened 6 years ago

toonvanstrijp commented 6 years ago

I can't figure it out how to center my SVG...

screen shot 2017-11-27 at 23 34 47

The code I'm using:

 let icon = UIView(SVGNamed: "icon_english") { (svgLayer) in
       svgLayer.fillColor = UIColor.white.cgColor
 }
 icon.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.5)
 self.layout(icon).width(size).height(size).edges().center()
mchoe commented 6 years ago

Hi @ToonvanStrijp. Without knowing too much about your icon_english SVG, can you make sure that there isn't any space around the shapes themselves? The library doesn't (and shouldn't) make assumptions about cropping any whitespace space around the graphic. Based on this, it looks like your graphic may have some extra space at the top.

You can also post the SVG file here and I'll be able to better assess the situation.