Я разрабатываю приложение в iOS, и моим требованием является скрытая строка HTML для строки NSAttributed и строка NSAttributed обратно в HTML. Первая часть, которую я смог достичь. Но NSAttributed String для HTML не происходит. Он возвращает строку в HTML, но не по желанию. Пожалуйста, смотрите код и выход ниже:Строка NSAttribute для HTML
HTML для NSAttributed Строка
NSString *htmlString = @"<div>Test, </div><div> </div><div>Test Test Test</div><div>Test Test Test </div><div> </div><div>Format text:</div><ul style="margin:0;padding-left:36pt;"><li><b>bold text</b></li><li><i>italic text</i></li><li><font color="red"><i>red text</i></font></li></ul><div> </div><div><i>The meeting body</i><i> </i><i>attachments</i></div>";
NSAttributedString *normal = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUTF8StringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: [NSNumber numberWithInt:NSUTF8StringEncoding]} documentAttributes:nil error:nil];
textView = [[UITextView alloc]initWithFrame:CGRectMake(10, 20, 500, 500)];
textView.attributedText = normal;
[self.view addSubview:textView];
Приведенный выше код работает по желанию ....
NSAttributed Строка HTML
NSAttributedString *s = textView.attributedText;
NSDictionary *documentAttributes = [NSDictionary dictionaryWithObjectsAndKeys:NSHTMLTextDocumentType, NSDocumentTypeDocumentAttribute, nil];
NSData *htmlData = [s dataFromRange:NSMakeRange(0, s.length) documentAttributes:documentAttributes error:NULL];
NSString *htmlString = [[NSString alloc] initWithData:htmlData encoding:NSUTF8StringEncoding];
Этот код не работает .. и я не получаю желания d выход .. выхода я получаю:
<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: 12.0px 'Times New Roman'; color: #000000; -webkit-text-stroke: #000000}
span.s1 {font-family: 'Times New Roman'; font-weight: normal; font-style: normal; font-size: 12.00pt; font-kerning: none}
</style>
</head>
<body>
<p class="p1"><span class="s1">Test<span class="Apple-converted-space"> </span></span></p>
<p class="p1"><span class="s1"> </span></p>
<p class="p1"><span class="s1">Test Test<span class="Apple-converted-space"> </span></span></p>
<p class="p1"><span class="s1"> </span></p>
<p class="p1"><span class="s1"> </span></p>
<p class="p1"><span class="s1"> </span></p>
<p class="p1"><span class="s1"> </span></p>
</body>
</html>
Что такое webEditor в вашей последней строке кода? –
Это объект WebView. –