Load local html into UIWebView using swift

前端 未结 13 2062
耶瑟儿~
耶瑟儿~ 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:10

    Swift 4.2, Xcode 10.1, WKWebView load HTML from file. UIWebView is deprecated.

    In apps that run in iOS 8 and later, use the WKWebView class instead of using UIWebView.

    import WebKit
    
    @IBOutlet weak var webView: WKWebView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
    
        let localFilePath = Bundle.main.url(forResource: "document_terms_of_use", withExtension: "html")
        let request = NSURLRequest(url: localFilePath!)
        webView.load(request as URLRequest)
    }
    

提交回复
热议问题