【问题标题】:Search For NSAttributedString with custom attribute and Remove it? How to?搜索具有自定义属性的 NSAttributedString 并删除它?如何?
【发布时间】:2010-08-06 13:01:25
【问题描述】:

我在 NSTextView 中有一个占位符字符串,一个空格字符,我想在将来删除它。我的策略是为 NSAttributedString 分配一个自定义属性并在 [NSTextView string] 上执行搜索以删除它。到目前为止,除了通过[NSTextStorage attributeRuns] 之外,我还没有找到这样做的好方法。有人对此有什么好主意吗?

谢谢!

【问题讨论】:

    标签: cocoa nstextview nsattributedstring


    【解决方案1】:

    查看我编写的自定义 NSAttributedString 属性的示例实现:http://aimannajjar.com/blog/1-How-to-Create-NSTextView-with-Facebook-like-Tags-Mentions.html

    基本上,我使用- enumerateAttributesInRange:options:usingBlock: 循环遍历所有属性,然后我有一个自定义绘图逻辑,该逻辑仅在属性为“标签”时运行。

    【讨论】:

      【解决方案2】:

      Apple 的 AttributedString Programming Guide 提供了一些示例,展示了如何使用 attribute:atIndex:effectiveRange: 和伴随方法循环一个属性字符串。 10.6 也有一个枚举器块。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-04-21
        • 1970-01-01
        • 2014-05-03
        • 1970-01-01
        相关资源
        最近更新 更多