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允许任何合理的包装?

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...