Hi all,

How can I display and edit text with multiple colors on iOS?

I looked into this months ago and got nowhere, but I've since noticed several 
iOS apps doing it. Even Apple's Mail app allows you to edit multi-colored text 
in a reply. So there must be a way I'm missing.

What I know:

1. UITextView (on iOS) is editable but will only show all the text in one 
color. NSTextView (on Mac OS X) does provide multiple color text editing.

2. UIWebView can display multi-colored text but is not editable. UIWebView's 
text metrics seem very similar to UITextView (ie if you ut the same text in 
both, the line spacings are the same and the character spacings are nearly the 
same).

3. iOS 3.2 and above state that they provides NSAttributedString support. You 
can fiddle around to get multiple colors in the objects, but there's still no 
way to actually display the colored text (which makes the NSAttributedString 
support seem worthless).

4. I can dive down into CoreText routines to render my own text using low level 
C calls. The coding is relatively complex and the result is not pretty. I got 
so far as displaying the multiple colored text, but it uses different metrics 
to UIWebView and UITextView. Most importantly, it doesn't support text editing.

5. I can display the multi-colored text in a UIWebView and overlay it with the 
same text in a UITextView, with the alpha set very low so it's practically 
invisible. When the user taps on the colored text, my UITextView receives the 
tap, changes alpha to 1.0, covering the UIWebView. The text appears to change 
from colored to black while the user edits. When they finish editing, the 
UITextView goes invisible again, the UIWebView updates its contents, so it 
appears to switch back from editing black to displaying colored. It works well, 
but I'd obviously prefer editable colored text.

Any ideas? Is anything I've said above incorrect?

As an example, one of my projects displays syntax coloring for SQL. Here are 
some very rough screenshots:
http://www.databare.com/trace.html
http://www.databare.com/column_trigger.html

Thanks,
Tom
BareFeetWare

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to