boundingRectWithSize的怪异行为:options:attributes:context:
我遇到一个与boundingRectWithSize:options:attributes:context:
相关的奇怪问题boundingRectWithSize:options:attributes:context:
这是代码
NSString *text = @"These long strings work"; CGSize maxSize = CGSizeMake(176.0f, MAXFLOAT); CGRect rect = [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:16.0]} context:nil]; CGSize size = rect.size;
我有一个使用此代码的Xcode iOS项目。 当我运行这个项目时, size
是(width=149.8125, height=18.1796875)
我在xcode中创build了一个新的单页应用程序项目,并在那里testing了相同的代码。 size
是(width=172.944031, height=19.0880013)
(它与在界面生成器中使用相同标题和相同字体创build的UILabel的帧大小相匹配)
苹果文档boundingRectWithSize:options:attributes:context
:
Calculates and returns the bounding rect for the receiver drawn using the given options and display characteristics
这种行为是否由于某些display characteristics
可能在不同的项目中有所不同?