How to display .svg image using swift

前端 未结 13 903
你的背包
你的背包 2020-11-30 00:37

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

I tried using UIImageView, which works for the .png & .jpg image formats, but not for the .svg extensi

13条回答
  •  忘掉有多难
    2020-11-30 00:59

    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
    

提交回复
热议问题