WkWebView won't loadHTMLstring

前端 未结 2 702
误落风尘
误落风尘 2020-12-15 23:09

I\'m trying to show in a WkWebView an html page that I previously downloaded and stored in a String.

This is how I setup my WkWebView:

    webView =          


        
2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-15 23:19

    SWIFT

    You might be making it a bit too complicated. This worked for me ...

    First, import WebKit

    Second, create an @IBOutlet under your class:

    @IBOutlet weak var webView: WKWebView!
    

    Third, place the following in your viewDidLoad():

    let htmlString:String! = "\(YourString)"
    webView.loadHTMLString(htmlString, baseURL: NSBundle.mainBundle().bundleURL)
    

    SWIFT 3 update

    webView.loadHTMLString(htmlString, baseURL: Bundle.main.bundleURL)
    

提交回复
热议问题