How to display .svg image using swift

前端 未结 13 886
你的背包
你的背包 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:49

    Swift 3.0 version :

    let path = Bundle.main.path(forResource: "svgNameFileHere", ofType: "svg")!
    if path != "" {
        let fileURL:URL = URL(fileURLWithPath: path)
        let req = URLRequest(url: fileURL)
        self.webView.scalesPageToFit = false
        self.webView.loadRequest(req)
    }
    else {
       //handle here if path not found
    }
    

    Third party libraries

    https://github.com/exyte/Macaw

    https://github.com/mchoe/SwiftSVG

    UIWebView and WKWebView booster to load faster

    https://github.com/bernikovich/WebViewWarmUper

提交回复
热议问题