2

使用 Macaw 主分支(出于 Swift 包管理器的原因)。

目标是刚好SVGView适合框架。我正确绘制的边框SVGViewRepresentable确认了所需的帧大小。但.scaleAspectFit只是没有给出放大/缩小SVGView以适应框架的结果。

struct SVGViewRepresentable: UIViewRepresentable {
    var svgName: String
    let size: CGSize

    func makeUIView(context: Context) -> SVGView {
        let node = try! SVGParser.parse(resource: svgName)

        let svgView = SVGView(node: node, frame: CGRect(origin: CGPoint.zero, size: size))
        svgView.backgroundColor = UIColor.clear
        svgView.layer.borderWidth = 1.0
        svgView.layer.borderColor = UIColor.blue.cgColor
        svgView.contentMode = .scaleAspectFit

        return svgView
    }

    func updateUIView(_ uiView: SVGView, context: Context) {

    }
}

struct MacawSVGView: View {
    var body: some View {
        GeometryReader { (geometry: GeometryProxy) in
            SVGViewRepresentable(svgName: "Tiger", size: geometry.size)
                .frame(width: geometry.size.width, height: geometry.size.height)
                .border(Color.red)
        }
    }
}
4

0 回答 0