.svg网址到UIImage iOS [英] .svg url to UIImage iOS

查看:70
本文介绍了.svg网址到UIImage iOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从服务器获取.svg网址。如何从.svg网址转换NSData并将其转换为UIImage。我收到类似 https://storage.googleapis.com/pgcdn/ca的网址/svg/lock.svg ,而我正在使用此代码

I am getting .svg urls from server. how can I convert NSData from .svg url and convert it into UIImage. I am getting url like "https://storage.googleapis.com/pgcdn/ca/svg/lock.svg" and I am using this code

        NSURL *url = [NSURL URLWithString:urlString];
        dispatch_queue_t callerQueue = dispatch_get_main_queue();
        dispatch_queue_t downloadQueue = dispatch_queue_create("com.test.svg", NULL);
        dispatch_async(downloadQueue, ^{
            NSData *imageData = [NSData dataWithContentsOfURL:url];
            UIImage *image = [UIImage imageWithData:imageData];
        }); 

此函数将图像显示为零值。

This function gives image as nil value.

推荐答案

您不能将 .svg 加载为 UIImage ,但是您可以加载带有 .svg 内容的 UIWebView ,因为iOS浏览器可以呈现SVG。

You can't load .svg as UIImage, but you can load a UIWebView with .svg content since the iOS browser can render SVG.

值得探索的一些线程可能是:

Some of the threads worth while exploring could be:


  1. 线程1

  2. 线程2

  3. 线程3

  1. Thread 1
  2. Thread 2
  3. Thread 3

您还可以探索第三方框架 SVGKit

You can also explore third party framework SVGKit.

这篇关于.svg网址到UIImage iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆