NSString sizeWithAttributes: returns different hei

2019-09-06 21:42发布

The line below returns a size with a larger height when I run it on an iOS8 device versus iOS7. It happens regardless of whether I'm building with iOS 7 or iOS 8 as my base SDK. Anyone else seeing this issue?

return [myString sizeWithAttributes:attributes];

标签: ios8
1条回答
乱世女痞
2楼-- · 2019-09-06 22:04

I answered my own question. The issue occurs when the string ends in a line break as below. This causes an issue because iOS 7 ignores trailing line breaks but iOS 8 doesn't.

myString = @"Some text.\n";

Removing the trailing line breaks before calling sizeWithAttributes: fixes the problem.

查看更多
登录 后发表回答