简体   繁体   English

UItextview带有换行路径的自动换行(swift)

[英]UItextview word wrapping with exclusion paths (swift)

I am working on an application that allows the user to add an image and move it around in a UITextView. 我正在开发一个允许用户添加图像并在UITextView中移动图像的应用程序。 The text flows around the image using exclusionPaths, but the words will break if there is not enough room on the remainder of the line instead of moving to the next line. 文本使用exclusionPaths在图像周围流动,但是如果该行的其余部分没有足够的空间而不是移至下一行,则单词将断开。

This is what I'm using to add the image and create the exclusionPaths for the text container 这就是我用来添加图像并为文本容器创建exclusionPaths的方法

textView.addSubview(imageview)
let imagePath = UIBezierPath(rect: imageview.frame)
textView.textContainer.exclusionPaths = imagePath

This is what is happening, notice how the words will break up to the right of the image 这就是正在发生的事情,请注意单词将如何在图像的右侧分解

This is what I want to happen. 这就是我要发生的事情。 The words should move to the next line if there is not enough room on the current line 如果当前行上没有足够的空间,则单词应移至下一行

Thank you for any help with this! 感谢您对此的任何帮助!

您可以使用imageView.bounds创建一个rect,然后尝试不确定但希望它能正常工作吗

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM