我想在UITextView中編輯HTML文本,此文本是在應用程序的Web版本中創建的,它允許您使用HTML編輯器創建文本編輯將與iOS的默認字體)Objective-C - 在UITextView中獲取簡單的HTML源代碼 - 無CSS樣式
我得到的文本在一個簡單的HTML如下編輯:
<p><b>html</b> <u>html</u> <i>html</i></p>
但對其進行編輯後,我得到的HTML文本的UITextView的代碼:
NSDictionary *exportParams = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType};
NSData *htmlData = [_txtDescricao.attributedText dataFromRange:NSMakeRange(0, _txtDescricao.attributedText.length) documentAttributes:exportParams error:nil];
NSString *descHtml = [[NSString alloc] initWithData:htmlData encoding:NSUTF8StringEncoding];
HTML文本返回與CSS樣式,如下圖所示:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 16.0px 'Helvetica Neue'; color: #000000; -webkit-text-stroke: #000000}
span.s1 {font-family: 'Helvetica Neue'; font-weight: bold; font-style: normal; font-size: 16.00pt; font-kerning: none}
span.s2 {font-family: 'Helvetica Neue'; font-weight: normal; font-style: normal; font-size: 16.00pt; font-kerning: none}
span.s3 {font-family: 'Helvetica Neue'; font-weight: normal; font-style: normal; font-size: 16.00pt; text-decoration: underline ; font-kerning: none}
span.s4 {font-family: 'Helvetica Neue'; font-weight: normal; font-style: italic; font-size: 16.00pt; font-kerning: none}
</style>
</head>
<body>
<p class="p1"><span class="s1">html</span><span class="s2"> </span><span class="s3">html</span><span class="s2"> </span><span class="s4">html</span></p>
</body>
</html>
我想簡單的HTML格式(不CSS)在UITextView中的HTML文本,作爲初始文本。
儘管它是一種有效的HTML格式,但我需要簡化格式的HTML文本(不含CSS),因爲我可以在Android版本的應用程序中編輯相同的文本,並且在Android中EditText不接受HTML文本CSS。
任何人都可以幫助我在沒有CSS的UITextView中獲取HTML文本?
謝謝。
我讀過這個問題幾次,並不明白它。到目前爲止,我得到了:您的應用程序提供了一個UITextView,它允許用戶輸入簡單的html。 'myTextView.text'將返回用戶輸入的任何內容。那是你要的嗎? – danh
myTextView.text返回文本:「HTML HTML HTML」,我希望得到這樣的文字:
HTML HTML HTML
–