如何将sizeWithFont转换为sizeWithAttributes(iOS 7)

时间:2014-03-26 06:25:25

标签: objective-c ios7 nsstring cgsize

如何在iOS 7 SDK中获得CGSize的{​​{1}}值,只想将以下代码行转换为NSString

sizeWithAttributes

1 个答案:

答案 0 :(得分:10)

你可以试试这个......

 NSDictionary *attributes = @{NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue" size:14]};

[text sizeWithAttributes:attributes]

CGRect rect = [text boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil];