title: Calculate html content height in UITextView failed
body: <p>I am using a UITableView with custom Cell to render HTML code into an UITextView with AttributedString. The UITextView fit the cell and I am using Auto-Layout to get the dynamic height based on the content of the UITextView. </p>
  
  <p>The html I use for the example is </p>
  
  <pre><code>&lt;h1&gt;hey this is a &lt;a href="www.google.com"&gt;link&lt;/a&gt;&lt;h1&gt;
  </code></pre>
  
  <p>It seems that the height found is incorrect.</p>
  
  <p><a href="https://i.stack.imgur.com/f151N.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/f151N.png" alt="enter image description here"></a></p>
  
  <p>I also tried to determine the height of the content base on the string with</p>
  
  <pre><code>func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -&gt; CGFloat {
      let text = content[indexPath.row]
      let tv = UITextView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bouds.width - 16 * 2, height: 1.0))
      tv.isScrollEnabled = false
      tv.textContainerInset = UIEdgeInsets.zero
      tv.textContainer.lineFragmentPadding = 0
      let height = TextContentCell.calculateHeight(textView: tv, data: text).height
      return height
  }
  </code></pre>
  
  <p>The calculateHeight function:</p>
  
  <pre><code>class func calculateHeight(textView:UITextView, data:String) -&gt; CGRect {
  
      var newFrame:CGRect!
      do {
          let attr = try NSAttributedString(data: data.data(using: String.Encoding.utf8)!, options: [NSAttributedString.DocumentReadingOptionKey.documentType : NSAttributedString.DocumentType.html,NSAttributedString.DocumentReadingOptionKey.characterEncoding: String.Encoding.utf8.rawValue], documentAttributes: nil)
          textView.attributedText = attr
      } catch {
          //Handle Exceptions
      }
  
      let fixedWidth = textView.frame.size.width
      textView.sizeThatFits(CGSize(width: fixedWidth, height: CGFloat.greatestFiniteMagnitude))
      let newSize = textView.sizeThatFits(CGSize(width: fixedWidth, height: CGFloat.greatestFiniteMagnitude))
      newFrame = textView.frame
      newFrame.size = CGSize(width: max(newSize.width, fixedWidth), height: newSize.height)
      print("height \(newFrame.height)")
      return newFrame
  }
  </code></pre>
  
  <p>This technique seems to return the exact same height that the dynamic height returned.</p>
  
  <p><a href="https://i.stack.imgur.com/GG2ZC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GG2ZC.png" alt="enter image description here"></a></p>
  
  <p>This problem occurs with html text no regular text.</p>
  
  <p><a href="https://i.stack.imgur.com/3LohH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3LohH.png" alt="enter image description here"></a></p>