NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc]initWithString:string];
NSMutableParagraphStyle *style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
style.lineBreakMode = NSLineBreakByWordWrapping;
[attribute addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, string.length)];
NSRange range = NSMakeRange(0, string.length);
NSDictionary *dic = [attribute attributesAtIndex:0 effectiveRange:&range];
CGSize size = [string boundingRectWithSize:CGSizeMake(100.0, 999999.0) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil].size;
NSLog(@"%f----%f",size.width, size.height);
NSMutableAttributedString
可以设置
NSFontAttributeName
NSParagraphStyleAttributeName
....
一般就使用这两个。font和paragraph