How to insert HTML into a UIWebView

人走茶凉 提交于 2019-12-02 16:38:46

This should do the trick:

NSString *myHTML = @"<html><body><h1>Hello, world!</h1></body></html>";
[myUIWebView loadHTMLString:myHTML baseURL:nil];
- (void)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL;

baseURL can be a fileURL to your resources folder if you have any images.

This example shows how we can se HTML into UIWebView and

func someFunction() {

    uiWebView.loadHTMLString("<html><body></body></html>", baseURL: nil)
    uiWebView.delegate = self as? UIWebViewDelegate
}

func webViewDidFinishLoad(_ webView: UIWebView) {
    //ready to be processed
}

Do not forget to extend a class from UIWebViewDelegate and nil the delegate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!