如何为 iPhone SMS 等文本的一部分划下划线? [英] How can I underline part of the text like iPhone SMS?

查看:81
本文介绍了如何为 iPhone SMS 等文本的一部分划下划线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 UILabel 来显示我的文本,在多行和 UILineBreakModeWordWrap 模式下,最大宽度为 200.
例如,这里是文本:

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".

如果文本以单行模式显示,使用 NSString 的 sizeWithFont 方法,我可以轻松计算第一个单词"的位置,然后覆盖 - (void)drawTextInRect:(CGRect)rect 绘制线条.

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?

推荐答案

有很多关于 iPhone 上缺少 NSAttributedString 的讨论,人们开始构建自己的文本布局系统来解决这个问题.这个领域有一些项目正在进行中.您可能想看看 Three20 项目 及其 TTStyledTextLabel.

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 SMS 等文本的一部分划下划线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆