如何在Swift中将blockquote应用于UIWebView

时间:2017-04-12 13:04:13

标签: swift uiwebview

我使用following Wordpress Editor Framework为用户提供富文本编辑器。

enter image description here

结果字符串是:

"<b>Bold is working&nbsp;</b><i>Italic as well</i>\n<blockquote>But sadly... blockquote is not\n<ul>\n\t<li>Lists are working</li>\n</ul>\n</blockquote>"

我的想法是,以相同的格式显示最终的字符串是使用UIWebView

let result = "<b>Bold is working&nbsp;</b><i>Italic as well</i>\n<blockquote>But sadly... blockquote is not\n<ul>\n\t<li>Lists are working</li>\n</ul>\n</blockquote>"
contentWebView.loadHTMLString("<html><body><font face='SourceSansPro' color='black'>\(result)</font></body></html>", baseURL: nil)

几乎所有东西都是我想要它的方式,但是块引用。

如何在第一个屏幕中将蓝色/灰色背景应用于blockquote?

enter image description here

非常感谢帮助。

1 个答案:

答案 0 :(得分:0)

我的解决方法:

func getFormattedHTMLString(_ entryString: String) -> String {
    let cssStyle = "<style>div {border: 0px solid black;background-color: #E1E8F2;padding-top: 10px;padding-right: 0px;padding-bottom: 10px;padding-left: 10px;}</style>"
    let removedBlockquoteEntries = entryString.replacingOccurrences(of: "<blockquote>", with: "<div>")
    let removedBlockquoteEndings = removedBlockquoteEntries.replacingOccurrences(of: "</blockquote>", with: "</div>")

    let result = "<html><head>\(cssStyle)</head><body><font face='SourceSansPro' color='black' size='5'>\(removedBlockquoteEndings)</font></body></html>"
    return result
}

我已将CSS代码添加到String以及HTML标记中。

然后我将<blockquote>标记替换为<div>个标记。

用法:webView.loadHTMLString(getFormattedHTMLString(txt), baseURL: nil)

Resul:

enter image description here