title: How to consistently draw NSAttributedString in UITextView in UITableViewCell
body: <p>I am having trouble getting consistent results from UITextViews in a UITableViewCell using NSAttributedStrings.</p>
  
  <p><strong>Inside - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath:</strong></p>
  
  <pre><code>UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  
  if (cell == nil) {
      cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  
      headerText = [[UITextView alloc]initWithFrame:CGRectZero];
      [headerText setUserInteractionEnabled:NO];
      headerText.tag = HEADER_TEXT;
      [cell.contentView addSubview:headerText]; 
  } else {
      headerText = (UITextView*)[cell.contentView viewWithTag:HEADER_TEXT];
  }
  
  //...setting up attributed strings
  
  
  [headerText setAttributedText:headerString];
  
  CGSize headerSize = [headerText sizeThatFits:CGSizeMake(246, CGFLOAT_MAX)];
  
  headerText.frame = CGRectMake(45, 8, headerSize.width, headerSize.height);
  </code></pre>
  
  <p><strong>Results:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/jtU3h.png" alt="Before Scrolling No contentinset"></p>
  
  <p>As you can see, the first two appear to draw the text in a way that I would expect/want.  In the last two the UITextView sizeThatFits method returns a much larger size then is required to draw the text and the text becomes centered in the frame rather then tight to the top of the frame.  This is an issue because I want to be able to layout other views based on the uitextview frame height.</p>
  
  <p><strong>After Scrolling out of frame and back in:
  <img src="https://i.stack.imgur.com/yX6ud.png" alt="enter image description here"></strong></p>
  
  <p>Now it gets even stranger, when the cells are reused, and the attributed string is set again.  the uitextview draws the text in an inconsistent way.</p>
  
  <p>Even Setting the contentInsets to</p>
  
  <pre><code>headerText.contentInset = UIEdgeInsetsMake(-8, -8, -8, -8);
  </code></pre>
  
  <p>Does not provide any sort of consistent results:</p>
  
  <p><img src="https://i.stack.imgur.com/dpOBX.png" alt="enter image description here"></p>
  
  <p>And After Scrolling with contentinset set:
  <img src="https://i.stack.imgur.com/66F1i.png" alt="enter image description here"></p>
  
  <p>Are there other attributes on UITextView that would allow me to get the behavior that I need?  </p>