You might have struggled a lot to load SVG (Scalable Vector Graphics) image(s) in your iPhone or iPad application using Objective C XCode. Objective C with Cocoa helps us to load png, jpg, tiff and other image formats file using UIImage and UIImageView but UIImageView will not allow you to load SVG files.
What are SVG images?
Scalable Vector Graphics (SVG) is a XML-based file format for two-dimensional vector graphics. SVG images and their behaviors are defined in XML text files. This means that they can be searched, indexed, scripted and, if required, compressed. As XML files, SVG images can be created and edited with any text editor, but it is often more convenient to create them with drawing programs such as Inkscape.
Now lets know how we can load SVG images in our iPhone or iPad application using Cocoa Objective-C. UIWebView allows us to load SVG images directly to our app. The code to load SVG image is given below.
Found interesting? Stay tuned at TechSpace for much more interesting solutions. Please leave a comment in comment box if you have any queries.NSString *path = [[NSBundle mainBundle] pathForResource:@"image" ofType:@"svg"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:path];
NSURLRequest *req = [NSURLRequest requestWithURL:fileURL];
[webView setScalesPageToFit:YES];
[webView loadRequest:req];