-[NSString sizeWithFont:] 在发布和调试版本中返回不同的结果
我已经使用此代码多次成功地调整 UILabel
的框架高度以适应动态文本:
(...)
CGSize labelSize = [thelabel.text sizeWithFont:font constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];
一切都很顺利,直到我开始使用 iOS5 SDK 构建我的应用程序。
对于armv6设备(iPhone3G/-),当构建用于调试时,标签大小是可以的,但是当构建用于发布时,检索到的高度值与宽度相同。我正在实际设备上运行这两个版本。
具有以下日志行的示例:
NSLog(@"labelSize: %f %f", labelSize.width, labelSize.height);
输出: iphone3G - 调试>
11 月 3 日星期四 18:22:50 未知应用程序名称[1071]:labelSize:115.000000 19.000000
iphone3G - 发布 >
11 月 3 日星期四 18:22:50 未知应用程序名称[1071]:labelSize:115.000000 115.000000
谁能帮助我或为我提供另一种解决方案来根据文本长度调整 UILabel
的高度?
我知道关于此方法有一些类似的问题,但它们没有解决这个特定问题。
I've used this code to resize a UILabel
's frame height to fit dynamic text several times with success:
(...)
CGSize labelSize = [thelabel.text sizeWithFont:font constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];
All was well until I started to build my apps using the iOS5 SDK.
For armv6 devices (iPhone3G/-), when building for debug, the label size is okay, but when building for release, the height value retrieved is the same as the width. I am running both of these builds on an actual device.
example with following log line:
NSLog(@"labelSize: %f %f", labelSize.width, labelSize.height);
output:
iphone3G - debug >
Thu Nov 3 18:22:50 unknown appname[1071] : labelSize: 115.000000 19.000000
iphone3G - release >
Thu Nov 3 18:22:50 unknown appname[1071] : labelSize: 115.000000 115.000000
Can anyone help or provide me with another solution to adjusting UILabel
's height based on the text length?
I'm aware there are some similar questions about this method, but they do not address this particular issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我发现 sizeWithFont:constrainedToSize:lineBreakMode: 将返回的内容有所不同,具体取决于您的代码运行的体系结构。我使用该函数来计算要在 UITableViewCells 中的 UILabels 中显示的字符串的高度,以便我可以计算单元格的最终高度。我在 iPhone 4 上使用了一种尺寸,而测试人员在他们的 iPod(旧的 armv6 设备)上使用了大尺寸的电池。
解决方案发布在这里: 有没有办法在 Xcode 4 中为 ARM 而不是 Thumb 进行编译?
我确信下面描述的优化修复也有效,但禁用拇指可能会让您保留优化设置?我不知道,你必须测试一下。
I've discovered a difference in what sizeWithFont:constrainedToSize:lineBreakMode: will return depending on which architecture your code is running on. I've used the function to calculate the height of strings I want to display in UILabels in UITableViewCells so that I can calculate the final height of the cell. I was getting one size on my iPhone 4, and a tester was getting big large cells on their iPod (old armv6 device).
The solution was posted here: Is there a way to compile for ARM rather than Thumb in Xcode 4?
I'm sure the optimization fix described below works as well, but disabling thumb might allow you to maintain your optimization settings? I don't know, you'd have to test this.
有同样的问题。
如果您点击 vfonseca 提供的链接,您将到达: 有没有办法在 Xcode 4 中为 ARM 而不是 Thumb 进行编译?
所选答案告诉您如何添加正确的编译器标志来防止这种情况。或者升级到 Xcode 4.3,它已修复此错误。
Had the same issue.
If you follow the link supplied by vfonseca, you arrive at: Is there a way to compile for ARM rather than Thumb in Xcode 4?
And the selected answer tells you how to add the correct compiler flags to prevent this. Alternatively upgrade to Xcode 4.3 which has fixed this bug.
我还是没能理解这个问题。
虽然,用另一种方法替换了 UILabel 调整大小方法:
所以,问题仍然存在,但是,暂时...我正在替换这种方法的代码出现。
如果有人对发生的事情有线索,请告诉我。我猜它+是 sizeWithFont 方法上的错误...但是当我们无法理解时总是更容易归咎于 SDK...:)
谢谢大家。干杯。
I still haven't managed to understand the problem.
Although, replaced the UILabel resize method with an alternative way:
So, the issue persists, but, for the time being... I'm replacing the code occurrences for this approach.
If someone come up with a clue about what happened, please let me know. I'm guessing it+s a bug on sizeWithFont method... but is always easier to blame on the SDK when we can't understand... :)
Thank you all. Cheers.