ios - UITextView 会缩短文本吗?

标签 ios uitextview textkit

如何知道 UITextView 是否会因为空间不足而缩短文本?我知道我可以使用 boundingRectWithSizesizeThatFit 进行计算,但是如果 UITextViewexclusionPaths 发生变化怎么办。我想在多边形中布置字符串,并增加多边形大小,直到布置字符串而不缩短。任何想法,如何获得 bool 返回,当前设置是否会缩短?

self.tv.textContainer.exclusionPaths = myArrayOfBezierPaths;

最佳答案

func isSizeFitForTextView() -> Bool{
    let layoutManager = self.textView.layoutManager
    let glyphIndex = layoutManager.glyphIndexForCharacter(at:( self.textView.text as NSString).length)

    let range = layoutManager.truncatedGlyphRange(inLineFragmentForGlyphAt: glyphIndex)

    return range.location != NSNotFound
}

关于ios - UITextView 会缩短文本吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40841898/

相关文章:

ios - UITextView – 无法在文本上设置下划线或删除线属性?

ios - 使用 Alamofire Swift 3 上传图像 (Base64)

ios - 从 Sprite 拖一条直线到 SpriteKit 中的手指位置

iphone - 如何让 UITextView 尊重 Interface Builder 中的换行符?

ios - UITextView 表示它在不存在时为空

ios - 如何在 Swift 中将阴影应用于 UITextView?

ios - 检测 iOS 中 UITextView 中属性文本的点击

ios - UIPageViewController/TextKit 计数页面数

ios -/Fabric.framework/运行 : Permission denied

javascript - history.back 在使用 Cordova 的 iOS 上不起作用