Priyanka Kanse Priyanka Kanse - 1 year ago 112
Swift Question

Swift Using SVG Files and Images

I have a .svg image file I want to display in my project.

UIImageView works only for .png & .jpg image formats, but not for the .svg extension. When used for .svg it returns nil.


Is there any way to display a .svg image using UIImageView or UIWebView ?

Answer Source

Try this code

var path: String = NSBundle.mainBundle().pathForResource("nameOfFile", ofType: "svg")!

        var url: NSURL = NSURL.fileURLWithPath(path)  //Creating a URL which points towards our path

       //Creating a page request which will load our URL (Which points to our path)
        var request: NSURLRequest = NSURLRequest(URL: url)
       webView.loadRequest(request)  //Telling our webView to load our above request
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download