NSString boundingRectWithSize边界不被尊重

有没有人知道在这里做的工作,或者我目前在做错什么.
CGSize boundingSize = CGSizeMake(288,9999);

CGRect boundingRect = [text boundingRectWithSize:boundingSize 
                                                 options:NsstringDrawingUsesLineFragmentOrigin
                                              attributes:[NSDictionary dictionaryWithObjectsAndKeys:theFont,NSFontAttributeName,nil]
                                                 context:nil];

代码在iOS7上运行(手机和SIM卡)时,返回的尺寸为416.3宽,高度为15.5.显然,boundingRectWithSize被忽略.有其他人遇到这个问题,如果有的话有任何人有关于如何解决这个问题的想法,还是有人指出我到哪去错了.

解决方法

根据 Apple documentation

You can use this method to compute the space required to draw the
string. The constraints you specify in the size parameter are a guide
for the renderer for how to size the string. However,the actual
bounding rectangle returned by this method can be larger than the
constraints if additional space is needed to render the entire string.
Typically,the renderer preserves the width constraint and adjusts the
height constraint as needed.

如果你指定一个固定的字体和太小的空间,一些东西必须给.在这种情况下,它是有界的空间.我猜你预期换行.宽度288允许任何合理的包装?

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...