6

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.

Harsh Jaiswal
  • 256
  • 1
  • 3
  • 5

1 Answers1

2

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. Thread 1
  2. Thread 2
  3. Thread 3

You can also explore third party framework SVGKit.

Community
  • 1
  • 1
Abhinav
  • 37,684
  • 43
  • 191
  • 309