首页 > 解决方案 > 如何使用 Macaw iOS 库从 url 显示 svg

问题描述

我需要在我的应用程序中显示 svg。svg 在服务器上可用,可以使用 url 访问。我正在尝试使用https://github.com/exyte/Macaw-Examples上提供的库。如何使用此库从 url 显示 svg。我也可以下载数据,但是库中没有将数据作为参数的方法?

标签: iosswift

解决方案


你需要这样使用SVGParser

class MyView: MacawView {

    required init?(coder aDecoder: NSCoder) {
        let url = ...
        let text = try! String(contentsOfFile: file.path, encoding: String.Encoding.utf8)
        let node = try! SVGParser.parse(text: text)
        super.init(node: node, coder: aDecoder)
    }

}

来源:https ://github.com/exyte/Macaw/issues/455


推荐阅读