title: Get number of lines in UITextView without contentSize.height
body: <p>I'm creating an image to export in my iOS app. I am using UIGraphicsBeginImageContext to draw the elements of the image but I've been struggling drawing a UITextView in the image.</p>
  
  <p>First I create a parent view for rendering:</p>
  
  <pre><code>var parentView : UIView = UIView(frame: CGRectMake(0, 0, 700, 700))
  </code></pre>
  
  <p>Then I programatically create the textView and add all the properties. I give it x=100 and y=100 to align the text in the image. Width = 500 is good to have a margin of 100px on each side:</p>
  
  <pre><code>var textView: UITextView = UITextView(frame: CGRectMake(100, 100, 500, 350))
  textView.text = myText
  textView.textContainerInset = UIEdgeInsetsMake(20, 20, 20, 20)
  textView.backgroundColor = UIColor(red: 255, green: 255, blue: 255, alpha: 0.70)
  textView.font = UIFont(name: "Helvetica Neue Light Italic", size: 35)
  </code></pre>
  
  <p>Then I render the textview in context by adding it as a subview to the parent view and then I get the image for export:</p>
  
  <pre><code>parentView.addSubview(textView)        
  parentView.layer.renderInContext(UIGraphicsGetCurrentContext())    
  var newIMG = UIGraphicsGetImageFromCurrentImageContext()
  </code></pre>
  
  <p>The problem is that the height is fixed to 350px, but sometimes the text is not long enough to use all that area. Ideally I would like to know how many lines will my text use, so I can give it a proportional height and not have a white unused area (see pic for example):</p>
  
  <p><a href="https://i.stack.imgur.com/P6JWQ.png" rel="noreferrer"><img src="https://i.stack.imgur.com/P6JWQ.png" alt="Info"></a>
  Any ideas on how to render the text view with a proportional height? Thanks a lot!</p>