Skip to content

Instantly share code, notes, and snippets.

View bogaevskyi's full-sized avatar

Andrew Bogaevskyi bogaevskyi

  • Kharkiv, Ukraine
View GitHub Profile
@matt-curtis
matt-curtis / gist:f9efbd2c2df1b77e3471
Last active January 22, 2018 14:48
Get number of lines in UITextView (iOS 7 compat.)
id<UITextInputTokenizer> tokenizer = textView.tokenizer;
UITextPosition *pos = textView.endOfDocument;
NSInteger lines = 0;
while (true){
UITextPosition *lineEnd = [tokenizer positionFromPosition:pos toBoundary:UITextGranularityLine inDirection:UITextStorageDirectionBackward];
if([textView comparePosition:pos toPosition:lineEnd] == NSOrderedSame){
pos = [tokenizer positionFromPosition:lineEnd toBoundary:UITextGranularityCharacter inDirection:UITextStorageDirectionBackward];