我如何知道 UIlabel 最多可以包含 NSString 中的哪一部分?
- 我的 iPad 上有两个并排的标签,每个标签占据了一半的屏幕。
- 我不想使用滚动视图。
- 我只希望左侧标签包含其可以进行的准确测试量,并希望其余标签转到右侧标签。
如何获取固定大小的 UILabel 可以包含的字符串的长度?
- I have two labels side by side in the ipad with each taking half the screen.
- I dont want to use the scrollview.
- 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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:
请用我的代码参考这个问题,了解我如何解决几乎相同的问题:CTFrameGetVisibleStringRange相当于iOS编程?
Refer to this question with my code on how I solved pretty much the same problem: CTFrameGetVisibleStringRange equivalent for iOS programming?