NSString sizeWithAttributes: returns different hei

2019-09-06 22:11发布

问题:

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];

回答1:

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.



标签: ios8