【问题标题】:UItextview word wrapping with exclusion paths (swift)带有排除路径的 UItextview 自动换行(swift)
【发布时间】:2019-02-27 00:09:12
【问题描述】:

我正在开发一个允许用户添加图像并在 UITextView 中移动它的应用程序。文本使用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

感谢您对此的任何帮助!

【问题讨论】:

    标签: ios swift uitextview line-breaks exclusionpath


    【解决方案1】:

    你能不能用 imageView.bounds 创建一个矩形,然后试一试,不确定但希望它能工作

    【讨论】:

    • 我不确定我是否理解,但如果您指的是“UIBezierPath(rect: imageview.frame)”,将“frame”更改为“bounds”并没有帮助。问题是文本在行尾换行并将单词拼写。
    • 我认为您设置排除路径的方式需要进行位修改,您可以参考下面的链接并滚动直到您看到文章中的排除路径部分,基本上他们使用 textview.convertRect:fromView 方法计算 rect @987654321 @
    • 我在我的项目中实现了 textview.convertRect:fromView 方法,但仍然遇到同样的问题,当图像没有足够的空间容纳单词而不是将单词移到下一行。
    • 暂时你能不能把self.textView.layoutManager.hyphenationFactor = 1.0,我也在寻找我们是否可以通过子类化layoutManager来获得连字符的单词范围并将它们移动到下一行
    • 好的,谢谢,如果您发现任何其他问题,请及时通知我
    猜你喜欢
    • 2017-11-17
    • 2014-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多