IOS 7 and above:
UIBezierPath * imgRect = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 100, 100)]; self.textView.textContainer.exclusionPaths = @[imgRect];
Swift (credit to Bart van Kuyku):
let exclusionPath = UIBezierPath(rect: CGRectMake(0, 0, 100, 100)) self.textView.textContainer.exclusionPaths = [exclusionPath]
Gil margolin
source share