如何使用 swift 显示 .svg 图像 [英] How to display .svg image using swift

查看:16
本文介绍了如何使用 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 图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆