.svg网址到UIImage iOS [英] .svg url to 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:
- Thread 1
- Thread 2
- Thread 3
您还可以探索第三方框架 SVGKit
You can also explore third party framework SVGKit.
这篇关于.svg网址到UIImage iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!