I have a UITableViewCell containing a UITextView and a UIImageView. The text view has scrolling disabled. The UITableViewCell does use auto layout to calculate its height to fit the content.
If there is more text than in the screenshot I want the text to flow around the image and use the space below it too. Therefore I use exclusion path on the text view. The exclusion Path gets set correctly and the text flows around the image.
Exclusion paths must be set after auto layout has calculated the frames. As the exclusion path blocks some view space on the text view the containing text does not fit any more in the height auto layout calculated for the text view.
How can I make this work together with auto layout?
I tried to set a height constraint on the text view after setting exclusion paths:
let size = textView.sizeThatFits(CGSize(width: textView.frame.size.width, height: CGFloat(MAXFLOAT)))
textView.heightAnchor.constraint(equalToConstant: size.height).isActive = true
This does not help. I need to call layoutSubviews()
on the UITableViewCell to force it to recalculate its height. However this will create an endless loop as I set my exclusion paths in viewDidLayoutSubviews()
.