SwiftSVG icon indicating copy to clipboard operation
SwiftSVG copied to clipboard

How to center SVG?

Open alexanderkhitev opened this issue 6 years ago • 2 comments

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 avatar Sep 11 '18 19:09 alexanderkhitev

@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)

dhruveonmars avatar Apr 26 '19 21:04 dhruveonmars

Hey @dhruveonmars ! I'll try it later. Thank you!

alexanderkhitev avatar Apr 27 '19 16:04 alexanderkhitev