0

How to know wether UITextView will shorten text because lack of space? I know I can calculate with boundingRectWithSize and sizeThatFit, but what if exclusionPaths of the UITextView is changed. I want lay out string in a polygon, and increase polygon size, until string laid out without shortening. Any idea, how can get a bool return, wether current setup will shorten?

self.tv.textContainer.exclusionPaths = myArrayOfBezierPaths;
János
  • 32,867
  • 38
  • 193
  • 353

1 Answers1

2
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
}
wj2061
  • 6,778
  • 3
  • 36
  • 62