我们如何在Cocoa中测量文本的可见边界? [英] How do we measure visible bounds of text in Cocoa?

查看:133
本文介绍了我们如何在Cocoa中测量文本的可见边界?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面列出的方法没有给出Cocoa中文本的确切可见边界。我们如何获得?

None of the methods listed below give the exact visible bounds of a text in Cocoa. How do we obtain that?


  • NSString ' boundingRectWithSize:options:属性: c>

  • NSAttributedString

  • NSLayoutManager usedRectForTextContainer: / li>
  • NSString's boundingRectWithSize:options:attributes:
  • NSAttributedString's boundingRectWithSize:options:
  • NSLayoutManager's usedRectForTextContainer:

为了说明这一点,这里是屏幕截图使用上述第二种方法的结果,如此示例代码段所示。

To illustrate this, here's a screenshot of the result of using the second method above as shown in this sample code snippet.

推荐答案

这里是我编码的解决方案。欢迎任何改进建议。

程式码片段: http://pastebin.com/qJMKwvau

屏幕截图: http://ScrnSht.com/jskyqs

Here's the solution I coded up. Any suggestions for improvements are most welcome.
code snippet: http://pastebin.com/qJMKwvau
screenshot: http://ScrnSht.com/jskyqs

这篇关于我们如何在Cocoa中测量文本的可见边界?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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