iOS에서 응용 프로그램을 개발 중이며 HTML 문자열을 NSAttributed 문자열로 변환하고 NSAttributed 문자열을 HTML로 변환해야합니다. 첫 번째 부분은 달성 할 수있었습니다. 그러나 NSAttributed String to HTML은 일어나지 않습니다. 문자열을 HTML로 반환하지만 원하는 것은 아닙니다. 아래 코드와 출력을 참조하십시오NSAttribute 문자열을 HTML로
NSAttributed 문자열이 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];
에
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>
마지막 코드 줄에는 어떤 웹 에디터가 있습니까? –
WebView 개체입니다. –