How to display .svg image using swift(如何使用 swift 显示 .svg 图像)
问题描述
我有一个 .svg 图像文件,我想在我的项目中显示.
I have a .svg image file I want to display in my project.
我尝试使用 UIImageView,它适用于 .png &.jpg 图像格式,但不适用于 .svg 扩展名.有没有办法使用 UIWebView 或 UIImageView 显示 .svg 图像?
I tried using UIImageView, which works for the .png & .jpg image formats, but not for the .svg extension. Is there any way to display a .svg image using UIWebView or UIImageView ?
推荐答案
试试这个代码
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
这篇关于如何使用 swift 显示 .svg 图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!