这被 [string boundingRectWithSize:options:attributes:context] 取代。“技巧”是创建一个包含您之前使用的字体和换行模式的属性字典。在您的情况下,应该是:
// Create a paragraph style with the desired line break mode
NSMutableParagraphStyle *paragraphStyle = [[[NSMutableParagraphStyle alloc] init] autorelease];
paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
// Create the attributes dictionary with the font and paragraph style
NSDictionary *attributes = @{
NSFontAttributeName:detailTextFont,
NSParagraphStyleAttributeName:paragraphStyle
};
// Call boundingRectWithSize:options:attributes:context for the string
CGRect textRect = [string boundingRectWithSize:CGSizeMake(widthOfTextView, 999999.0f)
options:NSStringDrawingUsesLineFragmentOrigin
attributes:attributes
context:nil];
float height = textRect.size.height;
如果您不使用段落样式,您将获得默认的 NSLineBreakByWordWrapping。