【问题标题】:Macaw SVG Image金刚鹦鹉 SVG 图像
【发布时间】:2020-10-21 06:04:40
【问题描述】:

所以我试图让 SVG 图像在 SwiftUI 中显示,但是插件 Macaw 的文档写得不好 - 根据 GitHub。

那么我怎样才能使下面的代码工作呢?

首先我在安装 pod 后导入它:

import Macaw

然后我添加这个:

SVGImage(svgName: "location")
                                       .frame(width: 550, height: 550)

但是我得到:

Cannot find 'SVGImage' in scope

我还安装了SVGKit,我正在尝试让它与它一起工作。

【问题讨论】:

    标签: swift swiftui svgkit macaw


    【解决方案1】:

    看起来你拿走了first part of this SO answer

    但是忘了实现 SVGImage struct

    import SwiftUI
    import Macaw
    
    struct SVGImage: UIViewRepresentable {
    
        var svgName: String
    
        func makeUIView(context: Context) -> SVGView {
            let svgView = SVGView()
            svgView.backgroundColor = UIColor(white: 1.0, alpha: 0.0)   // otherwise the background is black
            svgView.fileName = self.svgName
            svgView.contentMode = .scaleToFill
            return svgView
        }
    
        func updateUIView(_ uiView: SVGView, context: Context) {
    
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多