4

I have to create the view in which I have to open .svg extension file in iOS project. I have some doubts for this .svg extension

  1. Can we open .svf file directly in iOS like .png or any other images?
  2. Or we have to use any different thing to open this file.
Nishi
  • 683
  • 1
  • 12
  • 31

4 Answers4

6

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

See also these questions: How to render SVG images in iphone without uiwebview?, How can I load vector image directly with iPhone SDK?, how to render all kind of svg files in iphone?

Community
  • 1
  • 1
nneonneo
  • 171,345
  • 36
  • 312
  • 383
  • Thanks a lot..... If you have demo for this type of task. Please share with me. – Nishi Aug 27 '12 at 06:13
  • If you feel that this question is a duplicate mark it as such, don't post links to other StackOverflow posts as an answer (this answer is in the LQ review queue). – JAL Sep 08 '15 at 20:44
2

PocketSVG will allow you to display and manipulate the lines of an SVG file.

PocketSVG *myBezier = [[PocketSVG alloc] initFromSVGFileNamed:@"BezierCurve1-iPad"];    
UIBezierPath *myPath = myBezier.bezier;

CAShapeLayer *myShapeLayer = [CAShapeLayer layer];
myShapeLayer.path = myPath.CGPath;

[self.view.layer addSublayer:myShapeLayer];
Peter DeWeese
  • 18,141
  • 8
  • 79
  • 101
Eric
  • 16,003
  • 15
  • 87
  • 139
  • 1
    I was going to give this a +1, but since PocketSVG only handles SVGs with one path, I'm not going to up it at the moment. – Gordon Dove Dec 30 '13 at 13:53
  • 1
    @GordonDove That's a bit ridiculous. I'm pretty sure my post answers OP's question *and* suggests a good approach to the problem. But hey, I'm so sorry that free open-source libraries don't do all your work for you... On a more constructive note, how about you add support for multi path SVGs to PocketSVG and submit a pull request? – Eric Dec 30 '13 at 17:24
1

To complete this answer, now SVGKit handle full SVG files and render them as images.

You can also manipulate paths and capture touched path.

Hope this helps

iGranDav
  • 2,450
  • 1
  • 21
  • 25
0

Starting Xcode 12, you can add the image in your Assets Catalog and do this.

let image = UIImage(named: "SomeSVGImageInYourAssetsLibrary")

This is available for

macOS 10.15 or later, iOS 13 or later, iPadOS 13 or later

ref: https://developer.apple.com/documentation/xcode-release-notes/xcode-12-beta-release-notes

Ted
  • 22,696
  • 11
  • 95
  • 109