SwiftSVG
SwiftSVG copied to clipboard
How to center SVG?
Hello! After performing the resizeToFit function, the SVG image has an empty space on the right side between itself and the containerView, please tell me how to fix it?
This is example code
let url = Bundle.main.url(forResource: maskSVGName, withExtension: "svg")!
let containerView = UIView()
containerView.frame = borderFrame
containerView.layer.zPosition = 2000
let borderView = UIView(SVGURL: url) { (svgLayer) in
svgLayer.lineWidth = solidBorderStyle.lineWidth
svgLayer.strokeColor = UIColor.black.cgColor
svgLayer.fillColor = UIColor.clear.cgColor
svgLayer.resizeToFit(containerView.bounds)
}
containerView.addSubview(borderView)
self.supernode?.view.insertSubview(containerView, at: 0)```
@alexanderkhitev what I got to work for me, was to set the frame of the svg view before adding it to the container view.
So, for your code this should work;
borderView.frame = containerView.frame
and then
containerView.addSubview(borderView)
Hey @dhruveonmars ! I'll try it later. Thank you!