Last active
December 10, 2019 16:38
-
-
Save alexpersian/2aba30eea0691270a97457777022c98e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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