关于 boundingRectWithSize 计算\n不准

+(CGFloat)heightOfString:(NSString*)string withConstrainSize:(CGSize)size withAttributes:(NSDictionary*)attributes{

CGFloat height = 0;

string = [string stringByReplacingOccurrencesOfString:@"\r" withString:@""];

NSArray* stringArray = [string componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"\n"]];

for (NSString* string in stringArray) {

if (string.length > 0) {

CGRect bounds = [string boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:attributes context:nil];

height += bounds.size.height;

}

}

return height;

}

你可能感兴趣的:(关于 boundingRectWithSize 计算\n不准)