Load local html into UIWebView using swift

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

    This worked for me (Xcode 8, Swift 3)

    @IBOutlet weak var webViewer: UIWebView!

    override func viewDidLoad() {
        super.viewDidLoad()
    
        let localfilePath = Bundle.main.url(forResource: "homeInfo", withExtension: "html");
        let myRequest = NSURLRequest(url: localfilePath!);
        webViewer.loadRequest(myRequest as URLRequest);
        self.view.addSubview(webViewer)
    }
    

提交回复
热议问题