Skip to content

Instantly share code, notes, and snippets.

@axelrivera
Forked from wess/gist:5161817
Created December 3, 2013 00:43
Show Gist options
  • Save axelrivera/7761921 to your computer and use it in GitHub Desktop.
Save axelrivera/7761921 to your computer and use it in GitHub Desktop.
@implementation UITextView (Annex)
@dynamic visibleTextRange;
- (NSRange)visibleTextRange
{
CGRect bounds = self.bounds;
CGSize textSize = [self.text sizeWithFont:self.font constrainedToSize:bounds.size];
UITextPosition *start = [self characterRangeAtPoint:bounds.origin].start;
UITextPosition *end = [self characterRangeAtPoint:CGPointMake(textSize.width, textSize.height)].end;
NSUInteger startPoint = [self offsetFromPosition:self.beginningOfDocument toPosition:start];
NSUInteger endPoint = [self offsetFromPosition:start toPosition:end];
return NSMakeRange(startPoint, endPoint);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment