IPhone: traversing a UITextView around a UIImage?

How to get a UITextView to wrap its text around a UIImage, as in this image? alt text

Image size is not necessarily known before.

+6
iphone uitextview uiimageview textwrapping
source share
3 answers

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] 
+7
source share

Guil's answer in Swift:

 let exclusionPath = UIBezierPath(rect: CGRectMake(0, 0, 100, 100)) self.textView.textContainer.exclusionPaths = [exclusionPath] 
+2
source share

If anyone has a better solution, please bring it, but I usually had to go back to html to do this trick.

You can use two text elements and one imageView to achieve this programmatically, but I will be a couple of LOCs to write. You will need to find out the size of the image, set the first view of the table to be conveniently next to it, than showing where the line is longer than the visible one, turn it off in the next text element.

The same could be done with a simple local UIWebView

0
source share

All Articles