如何在UITextView中加载HTML?

如何在UITextView中加载HTML?,html,ios,objective-c,uitextview,Html,Ios,Objective C,Uitextview,我有一个带有achor标记的HTML内容。我只想在UITextView中加载HTML内容。您可以将HTML文档转换为nsattributestring,如下所示: // The HTML needs to be in the form of an NSString NSError *error = nil; NSAttributedString *attString = [[NSAttributedString alloc] initWithData:[HTML dataUsingEncodin

我有一个带有achor标记的HTML内容。我只想在
UITextView

中加载HTML内容。您可以将HTML文档转换为
nsattributestring
,如下所示:

// The HTML needs to be in the form of an NSString
NSError *error = nil;
NSAttributedString *attString = [[NSAttributedString alloc] initWithData:[HTML dataUsingEncoding:NSUTF8StringEncoding] options:@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute:@(NSUTF8StringEncoding)} documentAttributes:nil error:&error];
if (error) {
    NSLog(@"Error: %@ %s %i", error.localizedDescription, __func__, __LINE__);
} else {
    // Clear text view
    textView.text = @"";
    // Append the attributed string
    [textView.textStorage appendAttributedString:attString];
} 
如果遇到任何问题,请尝试在所有位置将编码更改为
NSASCIIStringEncoding

查看此信息