开发者

Search For NSAttributedString with custom attribute and Remove it? How to?

I have a placeholder string, a space character, in an NSTextView that I want to remove at a future time. My strategy is to assign the NSAttribut开发者_开发技巧edString a custom attribute and perform a search on the [NSTextView string] removing it. So far, I haven't found a good way to do this, outside of going through [NSTextStorage attributeRuns]. Anyone have a good idea for this?

Thanks!


Check out this example implementation that I wrote of custom NSAttributedString attribute: http://aimannajjar.com/blog/1-How-to-Create-NSTextView-with-Facebook-like-Tags-Mentions.html.

Basically, I loop though all attributes using - enumerateAttributesInRange:options:usingBlock: and then I have a custom drawing logic that only runs when the attribute is "Tag".


Apple's AttributedString Programming Guide has examples showing how to loop through an attributed string using attribute:atIndex:effectiveRange: and companion methods. There's an enumerator block, too, for 10.6.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜