title: iOS UITextView: How to create a double-spaced input text field?
body: <p>This is a follow up to <a href="https://stackoverflow.com/questions/19410170/ios-uitextview-increase-line-spacing-without-changing-the-height-of-the-cursor">this question</a>. I'm trying to create a double-spaced UITextView for entering text. </p>
  
  <p>In my custom UITextView, I've overwritten and -caretRectForPosition: to limit the height of the cursor. But now when I select text, the height of the selection rectangle was still too high:
  <img src="https://i.stack.imgur.com/k38hv.png" alt="red selection rectangle is too tall"></p>
  
  <p>I tried to overcome this by overriding UIView's -selectionRectsForRange. Unfortunately, the objects in that return array are UITextSelectionRects, which is an immutable subclass. So I made my own subclass, made the height mutable, and changed it in a loop like so:</p>
  
  <pre><code>- (NSArray *)selectionRectsForRange:(UITextRange *)range
  {
      NSArray *originalSectionRects = [super selectionRectsForRange:range];
      NSMutableArray *newSelectionRects = [[NSMutableArray alloc] initWithCapacity:originalSectionRects.count];
  
      // For all the UITextSelectionRects
      for (UITextSelectionRect *selectionRect in originalSectionRects) {
          // Use one with a custom height
          DCTextSelectionRect *newSelectionRect = [[DCTextSelectionRect alloc] initWithTextSelectionRect:selectionRect rectHeight:self.font.lineHeight];
          [newSelectionRects addObject:newSelectionRect];
      }
      return newSelectionRects.copy;
  }
  </code></pre>
  
  <p>Now the selection rectangles are the right size, but the blue handles used to grow &amp; shrink the selection area are trapped in the top left corner.</p>
  
  <p><img src="https://i.stack.imgur.com/vk1xB.png" alt="handles are trapped in the top left. selection height is correct"></p>
  
  <p>Any idea what's causing the handles to be in the wrong place? What can I try to get them in the right place?</p>