Load local html into UIWebView using swift

前端 未结 13 2083
耶瑟儿~
耶瑟儿~ 2020-11-28 22:27

This one is driving me crazy early this morning. I want to load some local html into a web view:

class PrivacyController: UIViewController {

    @IBOutlet w         


        
13条回答
  •  青春惊慌失措
    2020-11-28 23:13

    Here is succinct version for Swift 4

    1) Add import import WebKit

    2) Add WebKit.framework in your project

    @IBOutlet weak var webView: WKWebView!
    
    if let filePath = Bundle.main.url(forResource: "FILE_NAME", withExtension: "html") {
      let request = NSURLRequest(url: filePath)
      webView.load(request as URLRequest)
    }
    

提交回复
热议问题