4

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.

1

1 Answer 1

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.