Skip to content

Instantly share code, notes, and snippets.

@alexpersian
Last active December 10, 2019 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexpersian/2aba30eea0691270a97457777022c98e to your computer and use it in GitHub Desktop.
Save alexpersian/2aba30eea0691270a97457777022c98e to your computer and use it in GitHub Desktop.
// It's possible that the text is truncated not because of the line break mode,
// but because the text is outside the drawable bounds
if isTruncating == false {
// This gives us the range of all the characters that have been already laid out
// into the text container by the layout manager.
let glyphRange = layoutManager.glyphRange(for: textContainer)
// This provides the range of glyphs (not characters) that have been generated for the text container.
// Since a glyph is a graphical representation of a character, and more than one glyph can be used
// to represent a single character, this should always be equal or greater than the number of
// characters within the text container's layout buffer.
let characterRange = layoutManager.characterRange(forGlyphRange: glyphRange, actualGlyphRange: nil)
// If it is indeed less than the amount of characters we have in the text then that means
// the `UITextView` is not currently displaying all of its text content within its bounds.
isTruncating = characterRange.upperBound < text.utf16.count
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment