title: How to fix UITextView text content position in Swift
body: <p>I have <code>UIView</code> class and in this class have <code>UITextView</code> for use as inputText</p>
  
  <p>In <code>textViewDidChange</code> from row 2 through 5 with any inter, or adding text, I add the <code>UITextView</code> <code>bounds.size.height</code> as much as need.</p>
  
  <p>The problem is, in rows 3 and 5, first line text does not appear.
  To be roughly a row above its own space.
  And is created from the bottom of the empty space, without scrolling.</p>
  
  <p><a href="https://i.stack.imgur.com/J1XqR.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/J1XqR.jpg" alt=""></a></p>
  
  <p>But the text in the 4th row have exact position</p>
  
  <pre><code>class QuestionCell: UIView, UITextViewDelegate{
  
      var paragraph = UITextView()
  
      func setParagraph(){
          let frame = CGRect(x: 50,
                             y: 0,
                             width: forground.width-55,
                             height: forground.height)
          paragraph.frame = frame
          paragraph.isEditable = true
          paragraph.delegate = self
          // forground is some UIView in this View
          forground.addSubview(paragraph)
      }
      func textViewDidChange(_ textView: UITextView) {
         paragraph.bounds.size.height = paragraph.paragraphHeight
      }
  }
  
  extension UITextView{
      var paragraphHeight: CGFloat{
          let fixedWidth = self.width
          let newSize = self.sizeThatFits(CGSize.init(width: fixedWidth,
                                                           height: CGFloat(MAXFLOAT)))
          var newFrame = self.frame
          newFrame.size = CGSize.init(width: CGFloat(fmaxf(Float(newSize.width),
                                                           Float(fixedWidth))),
                                      height: newSize.height)
          return newSize.height
      }
  }
  </code></pre>