Created
July 18, 2016 17:20
-
-
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.
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
- (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