我如何知道 UIlabel 最多可以包含 NSString 中的哪一部分?

发布于 2024-09-18 00:47:46 字数 156 浏览 9 评论 0原文

  1. 我的 iPad 上有两个并排的标签,每个标签占据了一半的屏幕。
  2. 我不想使用滚动视图。
  3. 我只希望左侧标签包含其可以进行的准确测试量,并希望其余标签转到右侧标签。

如何获取固定大小的 UILabel 可以包含的字符串的长度?

  1. I have two labels side by side in the ipad with each taking half the screen.
  2. I dont want to use the scrollview.
  3. I just want the left label to contain the exact amount of test it can and want the remaining to go to the right label.

How can I get the length of the string that a fixed size UILabel can contain?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

耀眼的星火 2024-09-25 00:47:46

NSString 有一个方法可以返回给定字体的字符串的大小(以像素为单位)。您可以使用它来连续修剪字符,直到适合为止。
NSString sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode:

NSString has a method that can return the size (in pixels) for a string with a given font. You could use this to successively trim off characters until it fits.
NSString sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode:

原来分手还会想你 2024-09-25 00:47:46

请用我的代码参考这个问题,了解我如何解决几乎相同的问题:CTFrameGetVisibleStringRange相当于iOS编程?

Refer to this question with my code on how I solved pretty much the same problem: CTFrameGetVisibleStringRange equivalent for iOS programming?

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