Skip to content

Instantly share code, notes, and snippets.

@unboxme
Created July 18, 2016 17:20
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 unboxme/2f0198498be70d7a769a1c06b2943a89 to your computer and use it in GitHub Desktop.
Save unboxme/2f0198498be70d7a769a1c06b2943a89 to your computer and use it in GitHub Desktop.
Get amount of lines in UITextView without considering maximum lines, content size and etc.
- (NSUInteger)linesForTextView:(UITextView *)textView {
NSLayoutManager *layoutManager = [textView layoutManager];
NSUInteger numberOfLines, index, numberOfGlyphs = [layoutManager numberOfGlyphs];
NSRange lineRange;
for (numberOfLines = 0, index = 0; index < numberOfGlyphs; numberOfLines++) {
[layoutManager lineFragmentRectForGlyphAtIndex:index effectiveRange:&lineRange];
index = NSMaxRange(lineRange);
}
return numberOfLines;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment