-[NSAttributedString boundingRectWithSize] rect是html的错误

时间:2018-07-17 05:56:22

标签: ios

2 个答案:

答案 0 :(得分:0)

您还需要传递标记NSStringDrawingUsesFontLeading来考虑所使用的字体。

类似的东西(第41行):

CGRect rect = [str boundingRectWithSize:CGSizeMake(200, CGFLOAT_MAX)
options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading
context:NULL];

答案 1 :(得分:0)

NSRange tailRange = NSMakeRange(attributedString.length - 1, 1);
if (attributedString.length > 1 &&
    [[[attributedString attributedSubstringFromRange:tailRange] string] isEqualToString:@"\n"]) {
    [attributedString replaceCharactersInRange:tailRange withString:@""];
}

CGRect rect = [self.attributeString boundingRectWithSize:CGSizeMake(width,     CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading context:NULL];

ceilf(rect.size.height);