0

I want to create a text field with some text, that is styled with tags. Think of MS Word, some ext is bold, some is a headline, etc. The tags that style the text are not visible to the user, he just sees the text in bold.

How do I preserve these tags? I mean when I backspace over the closing bold-tag, for example, how do I preserve that and prevent that the rest of the text is now bold until the end?

I guess this is a pretty basic question for experiences programmers. Are there any algorithms or best practices? This problem surely has been solved before, any pointers?

(If this is of any concern, I develop for the iPhone OS and the text field will be a UITextView, but my question is more general I guess.)

Thanks in advance!

4

2 回答 2

0

与其将样式视为嵌入在文本中的打开/关闭标签,不如将它们视为 NSRange 并相应地调整它们。

于 2010-05-17T17:10:28.583 回答
0

从 3.2 开始,您可以使用 NSAttributesString。即使你自己滚动,它也是一个很好的参考。

属性应用于一系列字符。添加或删除字符时,范围会相应调整。

标签适用于 HTML 或 RTF 等扁平格式。在编辑过程中的内存中,您需要复杂的数据结构,例如 DOM 或 NSAttributedString。

于 2010-06-18T01:55:59.450 回答