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

5

如何在iOS 7 SDK中为NSString获取CGSize值?只需使用sizeWithAttributes将下面的代码转换即可。

CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:NSLineBreakByWordWrapping];

1个回答

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];

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接