如何知道UILabelView中显示的文本?

发布于 2024-09-03 02:39:58 字数 154 浏览 4 评论 0原文

如何知道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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情徒 2024-09-10 02:39:58

您要求的是一种测量文本的方法。 iPhone SDK 记录了一种方法,可以找出文本正文有多大,但不能找出给定空间内适合多少文本。您可以使用前者迭代地执行后者。

在 UIStringDrawing.h 中查找以下方法:

- (CGSize)sizeWithFont:(UIFont *)font forWidth:(CGFloat)width lineBreakMode:(UILineBreakMode)lineBreakMode;

使用此方法对字符串的不同长度子字符串进行(最好是二进制)搜索,直到找到适合特定高度的子字符串。您现在已经计算出第一个 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:

- (CGSize)sizeWithFont:(UIFont *)font forWidth:(CGFloat)width lineBreakMode:(UILineBreakMode)lineBreakMode;

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文