title: Set width and height of UITextView based on the dynamic text
body: <p>I'm building a chat application where each message are inserted into a row inside a table. Each row contains an avatar and a message. I want to set the width and height of the UITextArea as per the length of the text to put inside. </p>
  
  <p>Below is the code I've used. But here, both height and width are constant (200x50)</p>
  
  <p>PS: I'm a newbie to Swift and ios and I'm using Swift 3. Every code I got after searching is in objective-c or swift 2</p>
  
  <pre><code>func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
          let cell  = Bundle.main.loadNibNamed("ChatBox1", owner: self, options: nil)?.first as! ChatBox1
  
  
          let myTextField: UITextView = UITextView(frame: CGRect(x: 30, y: 20, width: 200.00, height: 50.00));
          cell.addSubview(myTextField)
          myTextField.isScrollEnabled = false
          myTextField.isUserInteractionEnabled = false
          myTextField.backgroundColor = UIColor.lightGray
          myTextField.text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry."
          myTextField.layer.cornerRadius = 5
          print(myTextField.intrinsicContentSize)
  
  
          let image = UIImage(named: "agent")
          let imageView = UIImageView(image: image)
          imageView.frame = CGRect(x: 0, y: 0, width: 40, height: 40)
          cell.addSubview(imageView)
  
  
          return cell
      }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/Vfa1Q.png" rel="nofollow"><img src="https://i.stack.imgur.com/Vfa1Q.png" alt="enter image description here"></a></p>