i have a string called htmlString that contains some开发者_JAVA百科 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?
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?
NSString *htmlStrings="
精彩评论