In my UITableViewCell subclass I have a UITextView and a UIImageView. The image covers the upper left corner of the UITextView and so I want to set an exclusion path so that the text wraps around the image. I'm doing it like this:
override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
let choiceCell = cell as! ItemChoiceTableViewCell
guard choiceCell.textView.textContainer.exclusionPaths.count == 0 else { return }
var frame = choiceCell.displayImageView.bounds
frame.size.height -= choiceCell.textView.frame.origin.y - choiceCell.displayImageView.frame.origin.y
choiceCell.textView.textContainer.exclusionPaths = [UIBezierPath(rect: frame)]
choiceCell.layoutSubviews()
}The height of the cell is usually a line too short though, and I believe what is happening is that the necessary size isn't being properly recalculated after the exclusion path is added in. I've tried various things in place of
layoutSubviews like setNeedsLayout and setNeedsDisplay but I can't get any of them to work properly.How do I force the size of the UITextView to recalculate after the exclusion path is added?