简体   繁体   English

iOS:从 JSON 显示 svg

[英]iOS : display svg from JSON

I'm trying to display a svg file in my iOS application.我正在尝试在我的 iOS 应用程序中显示一个 svg 文件。

The svg file is given to me by a REST API. svg 文件由 REST API 提供给我。 So I end up with an answer like this from the API :所以我最终从 API 得到了这样的答案:

{
   "response": {
      "data": {
         “var2”: “svgCodeXML”
      }, "status": "ok"
   } 
}

Currently I'm displaying it in a web view and it's displaying.目前我正在一个网络视图中显示它并且它正在显示。

I'd like to display the svg directly in my iOS app, without a web view.我想直接在我的 iOS 应用程序中显示 svg,没有网络视图。

I've been looking at the SVGKit library but I haven't found a way to do it.我一直在查看 SVGKit 库,但还没有找到方法。

Do anybody know how to achieve this purpose?有谁知道如何实现这个目的?

Thank you very much.非常感谢。

You can try using SVG kit.您可以尝试使用 SVG 套件。 You can find the code and examples here: https://github.com/SVGKit/SVGKit您可以在此处找到代码和示例: https : //github.com/SVGKit/SVGKit

Starting Xcode 12启动 Xcode 12

Asset Catalogs资产目录

New Features新功能

Added support for Scalable Vector Graphic (SVG) image assets.添加了对可缩放矢量图形 (SVG) 图像资产的支持。 These preserve their vector representation with deployment targets of macOS 10.15 or later, iOS 13 or later, and iPadOS 13 or later.这些使用 macOS 10.15 或更高版本、iOS 13 或更高版本以及 iPadOS 13 或更高版本的部署目标保留其矢量表示。 (18389814) (18389814)

source: https://developer.apple.com/documentation/xcode-release-notes/xcode-12-beta-release-notes来源: https : //developer.apple.com/documentation/xcode-release-notes/xcode-12-beta-release-notes

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM