Skip to content

Instantly share code, notes, and snippets.

@seanwolter
Created November 7, 2012 17:34
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 seanwolter/4033122 to your computer and use it in GitHub Desktop.
Save seanwolter/4033122 to your computer and use it in GitHub Desktop.
get the last word in a line UITextField
UITextPosition *firstRowStart = self.myTextView.beginningOfDocument;
UITextPosition *firstRowEnd = [self.myTextView.tokenizer positionFromPosition:firstRowStart
toBoundary:UITextGranularityLine
inDirection:UITextLayoutDirectionRight];
NSString *lastWord = nil;
while (!lastWord) {
UITextRange *range = [self.myTextView.tokenizer rangeEnclosingPosition:firstRowEnd
withGranularity:UITextGranularityWord
inDirection:UITextLayoutDirectionLeft];
lastWord = [self.myTextView textInRange:range];
firstRowEnd = [self.myTextView positionFromPosition:firstRowEnd offset:-1];
NSLog(@"%@",lastWord);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment