2017-04-12 32 views
0

我正在使用following Wordpress Editor Framework为用户提供富文本编辑器。如何在Swift中对UIWebView应用blockquote

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。

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

enter image description here

帮助是非常赞赏。

+0

那么,你的字符串未施加任何风格的块引用,这就是为什么你没有看到任何颜色。我确定编辑器正在引用一个CSS文件。 –

回答

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代码到字符串以及HTML标签。

然后我用<div>标签替换<blockquote>标签。

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

Resul:

enter image description here

相关问题