Search code examples
iosuiimageviewuitextviewword-wrapnsattributedstring

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.


Solution

  • This seems to do the trick:

    UIBezierPath * imgRect = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 100, 100)];
    self.textView.textContainer.exclusionPaths = @[imgRect];
    

    Swift,

    textView.textContainer.exclusionPaths = [UIBezierPath(...)]
    

    or just

    textView.textContainer.exclusionPaths = [UIBezierPath(...the image frame)]
    

    Works only from iOS 7 and up.