开发者

iOS - WebView and string

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="

Hello I m here

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜