2017-04-12 33 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

相關問題