Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrapping Text in a UITextView Around a UIImage WITHOUT CoreText

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.

like image 762
harryisaac Avatar asked Nov 04 '12 04:11

harryisaac


People also ask

What is the wrapping text around an image?

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.

What is wrapper text?

"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.

How do I keep text from wrapping around an image in CSS?

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).


2 Answers

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.

like image 144
Dannie P Avatar answered Sep 18 '22 12:09

Dannie P


In Swift 4:

self.textView.textContainer.exclusionPaths = [UIBezierPath(rect: imageView.frame)] 
like image 42
Callum Avatar answered Sep 19 '22 12:09

Callum