Iphone – How to underline part of the text like iPhone SMS

iphonensstringuilabel

I use an UILabel to show my text, in a multi-line and UILineBreakModeWordWrap mode, and the maximum width is 200.
For example, here is the text:

I really really want to underline first word and second word, could you help me?

And I want to underline "first word" and "second word".

If the text is shown in a single-line mode, with sizeWithFont method of NSString, I can easily calculate the position of "first word" and then override – (void)drawTextInRect:(CGRect)rect to draw the line.

But in multi-line mode, I don't know how to get the position. Do you have any idea?

Best Answer

There's quite some discussion about the missing NSAttributedString on the iPhone and people start building their own text layout systems to work around this. There are some projects going in this area. You may want to have a look at the Three20 project and its TTStyledTextLabel.