如何知道UILabelView中显示的文本?
如何知道UILabelView中显示的文本?我有一篇很大的文本,我将有 3 个 uilabel,代表 iPad 应用程序(例如《纽约时报》)的 3 列。当我将大文本放入第一列(UILabelView)时,我需要知道那里显示了多少文本。
如果您建议其他解决方案,请告诉我。 查理
How can I know the displayed text in the UILabelView? I have a large text and I am going to have 3 uilabels that represent 3 columns of an iPad App like NYTimes one. When I put the large text in the first column (UILabelView) I need to know how much of the text is displayed there..
If U suggest another solution please let me know.
Charly
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您要求的是一种测量文本的方法。 iPhone SDK 记录了一种方法,可以找出文本正文有多大,但不能找出给定空间内适合多少文本。您可以使用前者迭代地执行后者。
在 UIStringDrawing.h 中查找以下方法:
使用此方法对字符串的不同长度子字符串进行(最好是二进制)搜索,直到找到适合特定高度的子字符串。您现在已经计算出第一个 UILabel 可以显示多少文本。对每一列重复此操作。
您还可以在 CoreText 中使用 CTTypesetter,但那是 3.2 之前的版本。
What you are asking for is a way to measure text. The iPhone SDK documents a way to find out how big a body of text is, but not how much text fits in a given space. You can use the former to do the latter iteratively.
Look in UIStringDrawing.h for the following method:
Use this method to do a (preferably binary) search on different length substrings of your string until you find a substring that fits a particular height. You have now figured out how much text the first UILabel can display. Repeat for each column.
You could also use CTTypesetter in CoreText, but that is 3.2 forward.