Created
November 7, 2012 17:34
-
-
Save seanwolter/4033122 to your computer and use it in GitHub Desktop.
get the last word in a line UITextField
This file contains hidden or 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
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