【问题标题】:Objective C, Convert html to NSAttributeString and disable the hyperlinksObjective C,将 html 转换为 NSAttributedString 并禁用超链接
【发布时间】:2018-01-17 20:58:08
【问题描述】:

我正在使用

    [[NSAttributedString alloc] initWithData:[HTMLText                         
    dataUsingEncoding:NSUTF8StringEncoding] options:options 
    documentAttributes:NULL error:NULL];  

将 HTML 字符串转换为 AttributeString 并在 textView 中使用它,但是,我不希望文本中的超链接在 textView 中可点击,有什么办法可以删除文本后面的超链接?

【问题讨论】:

    标签: html ios objective-c uitextview nsattributedstring


    【解决方案1】:

    NS(Mutable)AttributedString 中的链接由属性NSAccessibilityLinkTextAttribute 表示。您可以删除单个属性。概述:

    • 制作属性字符串的可变副本
    • 使用enumerateAttribute:inRange:options:usingBlock: 定位所有链接
    • 在传递给上面的块中使用removeAttribute:range:删除链接

    阅读 Apple 的 NSAtributedString documentation。 高温

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-12
      • 1970-01-01
      • 2018-01-30
      • 2016-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多