Re: iOS multiple text colors in an editable text field
Re: iOS multiple text colors in an editable text field
- Subject: Re: iOS multiple text colors in an editable text field
- From: BareFeetWare <email@hidden>
- Date: Sun, 12 Dec 2010 14:05:38 +1100
On 12/12/2010, at 4:27 AM, Matt Neuburg wrote:
> NSAttributedString support is not "worthless" at all. Both CATextLayer and the Core Text drawing routines accept an NSAttributedString. With CATextLayer, displaying an attributed string is one line of code!
Actually, you're right. It's been a while since I used NSAttributedText and CoreText. Upon clearer reflection I think that it's more accurate to say that: while iOS 3.2 onward includes NSAttributedString, none of the iOS views support it. For example, UITextView doesn't accept an NSAttributedString the way NSTextView does. Also, the NSDictionary of keys for storing things like color isn't well defined.
As you and I pointed out, however, we can use a NSAttributedString in a "roll your own" view, using explicit CoreText routines to draw the text in a rect etc.
> However, that doesn't solve your problem.
Correct. I've been down that route, written my own classes to display a multi-colored NSMutableString in a custom view. It worked, looked OK, but has different metrics (font size and spacing) to UITextView and UIWebView. Most limiting, though, it that it doesn't provide any text editing ability. So a UIWebView is a better choice since it uses more standard metrics and provides at least some other niceties such as selecting text (but again, no editing).
> The solution is probably to assign yourself a different problem; there's no styled editable text on iOS and that's that. It doesn't pay to fight against the framework. m.
For the past few months and time being, I have just accepted the limit, instead changing to mono-colored when editing, then back to multi-colored to view.
But it seems that there is in fact styled editable text on iOS, since I see it in other apps, such as:
1. Apple Mail. If you reply to a messages containing multi-colored text, you can edit that text.
2. Pages
3. Textastic
4. HTML Edit
5. for i
6. Code Viewer 2
So my question is, how do they do it?
Although it's possible that some of these apps (which I haven't tried) actually only show color when not editing the text.
Thanks,
Tom
BareFeetWare
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden