iOS-WebView和字符串 [英] iOS - WebView and string

查看:86
本文介绍了iOS-WebView和字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为htmlString的字符串,其中包含一些以html格式设置的信息.我需要将这些信息放到webView中,以加载带有颜色和字体的整个html字符串.而且我需要知道琴弦的高度.我该怎么办?

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?

推荐答案

您想要执行以下操作:

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

您可以在此处查看文档: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIWebView_Class/Reference/Reference.html

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

这会将您的HTML加载到Web视图中,并使用您提供的路径作为其他文档的根.换句话说,您的html字符串可以引用其他文件(css,javascript等),并且baseURL用于查找使用相对路径的url.

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.

要获取高度,您可以分配UIWebView的委托,因为它有一个webViewDidFinishLoad:方法来告诉您何时呈现页面.然后,您可以使用UIWebView的方法-stringByEvaluatingJavaScriptFromString:

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?

这篇关于iOS-WebView和字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆