在UIWebview中加载字符串 [英] Loading string in UIWebview

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

问题描述

如何在UIWebview中加载如下所示的字符串

How to load a string like below in UIWebview

"\n
\nEgestas rhoncus auctor ac. Risus parturient, mid ultrices nisi.\U00a0
\nAugue ac elementum duis aliquet dolor elementum cum?\U00a0
\nTristique, augue sit lorem adipiscing dis!\U00a0
\nNunc nunc ultricies pellentesque dis dictumst enim
\n
\n"

我正在尝试在5个网页浏览中加载相同的内容。但它对我来说是崩溃..

I am trying to load this same content in 5 webviews..But it is crashing for me..

推荐答案

你应该使用:

[webView loadHTMLString:string baseURL:nil];

但请注意,您不会保留换行符。为了保留换行符,您需要将\ n替换为< \ br>(或任何有效的断行符号html),因此这将变为:

But note, that you won't preserve line breaks. To preserve line breaks you'll need to replace \n with <\br> (or any valid line breaking html), so this turns into:

[webView loadHTMLString:[string stringByReplacingOccurrencesOfString:@"\n" withString:@"<br/>"] baseURL:nil];

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

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