UILable 文本不完整

发布于 2024-10-07 16:29:04 字数 332 浏览 5 评论 0原文

嗨,我用谷歌搜索了一下,没有找到任何解决我的问题的方法。 我用一个大字符串填充 UILabels 文本,有时(并非每次都这样做)我的 UILabel.text 不完整(不是整个 NSString)。它主要发生在非常大的字符串上,但也发生在较短的字符串上。

有人遇到过这个问题吗,或者知道解决方法吗? 我真的不知道为什么会发生这种情况...

提示:我在 ScrollView 上使用带有 UILabel 的 IB。在视图的 ViewDidLoad 方法中,我使用 sizeWithFont 方法计算出 UILabel 的高度。 我在 IB 中使用 WordWrap、AlignBaseline 作为我的 UILabel

Hi i googled around a bit and didn´t find any solutions for my problem.
i fill a UILabels text with a large String, and sometimes (it doesn`t do so everytime) my UILabel.text is incomplete (not the whole NSString). It mostly happens with very large Strings but also with shorter ones.

Has anybody had that problem, or does know a workaround for this?
I really don`t know why this is happening...

Hint: I am using IB with a UILabel on a ScrollView. In the ViewDidLoad Method of the View i figure out the height of the UILabel with the sizeWithFont Method.
I use WordWrap, AlignBaseline for my UILabel in IB

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

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

发布评论

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

评论(2

南风起 2024-10-14 16:29:04

我确实将预期大小的方法更改为:

UIFont *labelFont           = [UIFont systemFontOfSize:14];
CGSize expectedLabelSize    = [testString sizeWithFont:labelFont 
                                  constrainedToSize:maximumLabelSize 
                                      lineBreakMode:UILineBreakModeWordWrap];

这是错误的:

CGSize expectedLabelSize    = [testString sizeWithFont:IBOutletUILabel.font 
                                  constrainedToSize:maximumLabelSize 
                                      lineBreakMode:UILineBreakModeWordWrap];

cobbal 是对的...

但我很困惑,因为它之前似乎忽略了换行符,因为我的标签大小发生了变化

i did change my method for the expected size to this:

UIFont *labelFont           = [UIFont systemFontOfSize:14];
CGSize expectedLabelSize    = [testString sizeWithFont:labelFont 
                                  constrainedToSize:maximumLabelSize 
                                      lineBreakMode:UILineBreakModeWordWrap];

this was wrong:

CGSize expectedLabelSize    = [testString sizeWithFont:IBOutletUILabel.font 
                                  constrainedToSize:maximumLabelSize 
                                      lineBreakMode:UILineBreakModeWordWrap];

cobbal is right...

but i am confused, because it seemed to be ignoring the newline characters before, cause my label size was variating

三生池水覆流年 2024-10-14 16:29:04

确保设置 numberOfLines 除了设置自动换行之外,还可以将其设置为 0。

Make sure you set the numberOfLines to 0 in addition to setting word wrapping.

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