iPhone: UITextView wrap around UIImage?

白昼怎懂夜的黑 提交于 2019-11-28 03:51:59

问题


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.


回答1:


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]



回答2:


Gil's answer in Swift:

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



回答3:


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



来源:https://stackoverflow.com/questions/4380652/iphone-uitextview-wrap-around-uiimage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!