iPhone: UITextView wrap around UIImage?
How do I get a UITextView to wrap its text around a UIImage like in this image?
The image size is not necessarily previously known.开发者_JAVA技巧
IOS 7 and above:
UIBezierPath * imgRect = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 100, 100)];
self.textView.textContainer.exclusionPaths = @[imgRect];
Swift (credit to Bart van Kuik):
let exclusionPath = UIBezierPath(rect: CGRectMake(0, 0, 100, 100))
self.textView.textContainer.exclusionPaths = [exclusionPath]
Gil's answer in Swift:
let exclusionPath = UIBezierPath(rect: CGRectMake(0, 0, 100, 100))
self.textView.textContainer.exclusionPaths = [exclusionPath]
If somebody has a better solution, please bring it on, but i usually had to revert to html to do this kind of trick.
You could use two textViews and one imageView to achieve this programmatically, but i'll be a couple of LOC to write. You would have to figure out the size of the image, set the first table view to fit nicely next to, than figure out where the string is longer than visible, cut it off an go on on the next textView.
The same could be achieved by a simple local UIWebView
精彩评论