views:

541

answers:

1

Hey guys,

I need to display some text on multiple views loaded on a UIScrollView. It should be centered both vertically and horizontally.

I did accomplish this with no problems using a UITextView, but now I need to perform a little bit of formatting in the middle of the text - some color changing and italics.

My first try was to use a UIWebView for that, declare some CSS for the <i> tag with the right color and it did work, but it's just too slow. Sometimes the view gets scrolled on the screen and takes a good second before it's text is updated.

I've thought Core Graphics, but some docs reading and google showed me this is a tough task. I mean, if it's the only option, I'll have to learn it. But before that, I'd like to know if there is anything else I should try.

So, could you guys point me in the right direction? Is there any other option or what do I need to search for drawing multi-line, centered, formatted text in Core Graphics?

+1  A: 

You can use a custom UILabel. Joe Hewitt (Facebook app developer) uses one and has open sourced much of his code. It is called Three20

I think what you want is the TTStyledTextLabel

coneybeare
Thank you! I'll check if that one works for me.
leolobato
I'll accept this answer since that is a starting point for me, but that component doesn't support any text justification other than Left. I'll try to implement centered justification, but I'm not sure it will be simple. Thanks!
leolobato
I wonder why the TTStyledTextLabel isn't more prominently advertised. The Three20 website only mentions the various high level components. While these are no doubt very useful, I'm guessing that low level views such as this text label might be even more interesting to many developers (myself included).
Mirko Froehlich