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:
我使用UILabel以多行和UILineBreakModeWordWrap模式显示我的文本,最大宽度为200.例如,这里是文本:
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.
如果文本以单行模式显示,使用NSString的sizeWithFont方法,我可以轻松地计算“第一个单词”的位置,然后覆盖 - (void)drawTextInRect:(CGRect)rect来绘制线条。
But in multi-line mode, I don't know how to get the position. Do you have any idea?
但在多线模式下,我不知道如何获得这个位置。你有什么主意吗?
2 个解决方案
#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.
关于iPhone上缺少NSAttributedString的讨论很多,人们开始构建自己的文本布局系统来解决这个问题。这个领域有一些项目。您可能想看看Three20项目及其TTStyledTextLabel。
#2
Use a UIWebView to display your text. That's what Apple recommends for rich text.
使用UIWebView显示文本。这就是Apple推荐的富文本。
#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.
关于iPhone上缺少NSAttributedString的讨论很多,人们开始构建自己的文本布局系统来解决这个问题。这个领域有一些项目。您可能想看看Three20项目及其TTStyledTextLabel。
#2
Use a UIWebView to display your text. That's what Apple recommends for rich text.
使用UIWebView显示文本。这就是Apple推荐的富文本。