gpt4 book ai didi

html - 如何在 UITextView 中加载 HTML?

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:01:22 25 4
gpt4 key购买 nike

我有一个带有 anchor 标记的 HTML 内容。我只想在 Text View 中加载该 HTML 内容。

最佳答案

您可以像这样将 HTML 文档转换为 NSAttributedString:

// 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

关于html - 如何在 UITextView 中加载 HTML?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29875315/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com