search

Home  >  Q&A  >  body text

Objective-c - TextKit path exclusion height calculation issue

To implement path exclusion by inserting images into articles

UITextView dynamically calculates height using:
boundingRectWithSize:options:context:

However, this method is not compatible with path exclusion, and the height will be much smaller than the actual height. However, there is no problem using the sizeThatFits: method, but the performance of sizeThatFits: is really worrying

Do you have any good solutions


Code:

// 此方法获取的高度会小,只会计算文本高度,不会包含被路径排除的部分
CGRect textViewFrame = self.textView.frame;
CGSize maxSize = CGSizeMake(CGRectGetWidth(textViewFrame), MAXFLOAT);
CGRect frame = [self.textView.attributedText boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading context:nil];

// 此方法正常,但性能很差
CGSize size = [self.textView sizeThatFits:maxSize];
大家讲道理大家讲道理2805 days ago540

reply all(1)I'll reply

  • 天蓬老师

    天蓬老师2017-05-02 09:26:31

    http://stackoverflow.com/questions/19196758/calculate-cell-height-for-textview-with-exclusion-paths

    reply
    0
  • Cancelreply