NSAttributedString 不在 Textview 中显示 NSLink

NSAttributedString not displaying NSLink in Textview

我有一个 NSAttributedString,它是 HTML 使用

制作的
NSAttributedString *decodedString = [[NSAttributedString alloc] initWithData:[encodedString dataUsingEncoding:NSUTF8StringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: [NSNumber numberWithInt:NSUTF8StringEncoding]} documentAttributes:nil error:nil];
self.story.attributedText = decodedString;

当我 运行 代码并查看 TextView (self.story) 时,HTML 中的所有文本和图像都会显示,超链接 (HTTP) 除外。

他们占据的 space 在那里,但没有链接

示例:超链接 ________________ 应该存在。 只是没有 ____ 它只是空白。

控制台显示 NSAttributedString 显示

{
    NSColor = "UIDeviceRGBColorSpace 0 0 0.933333 1";
    NSFont = "<UICTFont: 0x15654c230> font-family: \"Times New Roman\"; font-weight: normal; font-style: normal; font-size: 12.00pt";
    NSKern = 0;
    NSLink = "https://www.kickstarter.com/projects/1425492550/sesame-your-key-reinvented";
    NSParagraphStyle = "Alignment 4, LineSpacing 0, ParagraphSpacing 12, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n), DefaultTabInterval 36, Blocks (null), Lists (null), BaseWritingDirection 0, HyphenationFactor 0, TighteningFactor 0, HeaderLevel 0";
    NSStrokeColor = "UIDeviceRGBColorSpace 0 0 0.933333 1";
    NSStrokeWidth = 0;
    NSUnderline = 1;
}

但是找不到“https://www.kickstarter.com/projects/1425492550/sesame-your-key-reinvented”。

关于为什么会发生这种情况以及如何解决这个问题有什么想法吗?

我正在回答我自己的问题。

链接显示为白色(在白色背景上)并且无法点击,因此看起来好像它们不存在一样。

我用这段代码修复了它。

twocell.story.linkTextAttributes = @{NSForegroundColorAttributeName:[UIColor darkGrayColor]};
        NSMutableAttributedString *res = [twocell.story.attributedText mutableCopy];
        [res beginEditing];
        [res enumerateAttribute:NSUnderlineStyleAttributeName inRange:NSMakeRange(0,res.length) options:0 usingBlock:^(id value, NSRange range, BOOL *stop) {

            if (value){
                [res addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:range];
                [res endEditing];
                [twocell.story setAttributedText:res];
            }
        }];

将颜色更改为深灰色并添加下划线。