title: Getting CGRect for text in a UITextView for the purpose of highlighting with a CALayer
body: <p>I am trying to draw a transparent CALayer in a UITextView in order to highlight matched text in a search.</p>
  
  <p>I've figured out the correct way to do this, but still haven't found the correct coordinates.  I need to find the origin of the text container.  Right now, I get the textView's origin, and offset the layer's origin by that:</p>
  
  <pre><code>NSRange match = [[[self textView]text]rangeOfString:@"predict the future"];
  NSRange glyphRange = [manager glyphRangeForCharacterRange:match actualCharacterRange:NULL];
  
  CGRect textRect = [manager boundingRectForGlyphRange:glyphRange inTextContainer:[[self textView]textContainer]];
  
  CGPoint textViewOrigin = self.textView.frame.origin;
  textRect.origin.x += (textViewOrigin.x / 2);
  textRect.origin.y += (textViewOrigin.y / 2);
  
  
  CALayer* roundRect = [CALayer layer];
  [roundRect setFrame:textRect];
  [roundRect setBounds:textRect];
  
  [roundRect setCornerRadius:5.0f];
  [roundRect setBackgroundColor:[[UIColor blueColor]CGColor]];
  [roundRect setOpacity:0.2f];
  [roundRect setBorderColor:[[UIColor blackColor]CGColor]];
  [roundRect setBorderWidth:3.0f];
  [roundRect setShadowColor:[[UIColor blackColor]CGColor]];
  [roundRect setShadowOffset:CGSizeMake(20.0f, 20.0f)];
  [roundRect setShadowOpacity:1.0f];
  [roundRect setShadowRadius:10.0f];
  
  [[[self textView]layer]addSublayer:roundRect];
  </code></pre>
  
  <p>I get the following result if I move the text field, or if I don't divide the offsets by 2:
  <img src="https://i.stack.imgur.com/la0YY.jpgrdinates." alt="The layer frame is off"></p>
  
  <p>I'd like to know if i'm on the right track and also how to find the NSTextContainer object's origin if so.</p>