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

3.2以降、NSAttributesStringを使用できます。自分で転がしても参考になります。

属性は文字の範囲に適用されます。文字が追加または削除されると、それに応じて範囲が調整されます。

タグは、HTMLやRTFなどのフラット化された形式用です。編集中のメモリには、DOMやNSAttributedStringなどの複雑なデータ構造が必要です。

于 2010-06-18T01:55:59.450 に答える
0

スタイルをテキストに埋め込まれた開始/終了タグとして考えるのではなく、NSRanges の観点から考え、それに応じて調整します。

于 2010-05-17T17:10:28.583 に答える