Is there a way to wrap text from a UITextView
around a UIImage
without using CoreText
?
I have been playing around with attributed strings without much luck, and CoreText
just seems extremely complicated so I would rather stay out of it.
Wrapping a text means adjusting/wrapping text around an image. In HTML, we can either align the image on the right side of the text, or to the left, or to the center.
"Wrapping text" means displaying the cell contents on multiple lines, rather than one long line. This will allow you to avoid the "truncated column" effect, make the text easier to read and better fit for printing.
If you want to prevent the text from wrapping, you can apply white-space: nowrap; Notice in HTML code example at the top of this article, there are actually two line breaks, one before the line of text and one after, which allow the text to be on its own line (in the code).
This seems to do the trick:
UIBezierPath * imgRect = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 100, 100)]; self.textView.textContainer.exclusionPaths = @[imgRect];
Works only from iOS 7 and up.
In Swift 4:
self.textView.textContainer.exclusionPaths = [UIBezierPath(rect: imageView.frame)]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With