NSString sizeWithAttributes:在iOS 8和iOS 7中返回不同的高度 [英] NSString sizeWithAttributes: returns different height in iOS 8 versus iOS 7

查看:109
本文介绍了NSString sizeWithAttributes:在iOS 8和iOS 7中返回不同的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在iOS8设备上运行iOS7设备时,下面的行会返回一个更大的高度。无论我是使用iOS 7还是iOS 8构建我的基本SDK,都会发生这种情况。其他人是否看到此问题?

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


推荐答案

我回答了我自己的问题。当字符串以换行符结束时,会出现此问题,如下所示。这会导致问题,因为iOS 7会忽略尾随换行符,但iOS 8不会。

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

在调用sizeWithAttributes之前删除尾随换行符:修复问题。

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

这篇关于NSString sizeWithAttributes:在iOS 8和iOS 7中返回不同的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆