简体   繁体   English

我怎样才能像iPhone短信一样强调部分文字?

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

I use an UILabel to show my text, in a multi-line and UILineBreakModeWordWrap mode, and the maximum width is 200. 我使用UILabel以多行和UILineBreakModeWordWrap模式显示我的文本,最大宽度为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. 如果文本以单行模式显示,使用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? 你有什么主意吗?

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. 关于iPhone上缺少NSAttributedString的讨论很多,人们开始构建自己的文本布局系统来解决这个问题。 There are some projects going in this area. 这个领域有一些项目。 You may want to have a look at the Three20 project and its TTStyledTextLabel . 您可能想要查看Three20项目及其TTStyledTextLabel

Use a UIWebView to display your text. 使用UIWebView显示文本。 That's what Apple recommends for rich text. 这就是Apple推荐的富文本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM