NSAttributedString reporting incorrect sizes for UITextView sizeThatFits and boundingRectWithSize with correct options set

后端 未结 3 826
不思量自难忘°
不思量自难忘° 2021-02-15 00:26

I have an NSAttributedString that is reporting a boundingRectWithSize (and by extension a UITextView which improperly calculates its sizeThatFits) when the font size is decrease

3条回答
  •  北海茫月
    2021-02-15 00:36

    Create NSTextStorage object and init with the attributedString. and calculate bounds.

    NSTextStorage *attributedText = [[NSTextStorage alloc] initWithAttributedString:[[NSAttributedString alloc] initWithString:text attributes:@{NSFontAttributeName:systemFont}]];
    CGRect textRect = [attributedText boundingRectWithSize:CGSizeMake(textW, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin context:nil];
    

提交回复
热议问题