iOS - WebView and string

一世执手 提交于 2019-12-24 00:41:58

问题


i have a string called htmlString that contains some informations formatted in html. I need to put these info into a webView that load the entire html string, with color and fonts. And i need to know the string height. How can i do?


回答1:


You want to do something like:

[_webView loadHTMLString:htmlStr
                 baseURL:[NSURL fileURLWithPath:path]];

You can view the docs here: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIWebView_Class/Reference/Reference.html

This will load your HTML into the webview and use the path you provide as a root for other documents. In other words, your html string could reference other files (css, javascript, etc...) and the baseURL is used to locate the urls that use relative paths.

EDIT:

To get the height, you could assign the UIWebView's delegate as it has a webViewDidFinishLoad: method to tell you when the page is rendered. Then you could execute javascript on the page to determine the final height using UIWebView's method - stringByEvaluatingJavaScriptFromString:

This answer also seems pretty relevant: How to determine UIWebView height based on content, within a variable height UITableView?




回答2:


NSString *htmlStrings="

Hello I m here

"; [_webView loadHTMLString:htmlStrings baseURL:[NSURL fileURLWithPath:null]];

来源:https://stackoverflow.com/questions/7259331/ios-webview-and-string

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