views:

1834

answers:

2

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?

+3  A: 

Use a UIWebView to display your text. That's what Apple recommends for rich text.

Nikolai Ruhe
Yes, UIWebView can definitely solve my problem, but wouldn't it be too heavy to just show a sentence?
Neng
I have this feeling about UIWebView, too. But nevertheless, it's what Apple recommends. See my second answer.
Nikolai Ruhe
+3  A: 

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.

Nikolai Ruhe
TTStyledTextLabel is exactly what I wanted. Thanks a lot.
Neng