vladasha vladasha - 4 months ago 71
iOS Question

Break text that covers other views

Is it possible to break the text automatically, so the text isn't covering it, like the example below, in UITextview?

Image

Answer

Add CoreText Framework

import CoreText

Add the below code after adding the imageView to UITextView,

var exclusionPath = UIBezierPath(rect: CGRect(x: imageView.frame.orgin.x, y: imageView.frame.orgin.y, width: imageView.frame.size.width, height: imageView.frame.size.height))
textView.textContainer.exclusionPaths = [exclusionPath]
textView.addSubview(imageView)