How can I underline part of the text like iPhone SMS?

醉酒当歌 提交于 2020-01-24 10:13:23

问题


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?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/964027/how-can-i-underline-part-of-the-text-like-iphone-sms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!