title: How to generate an UIImage from custom text in Swift
body: <p>I am trying to generate an <code>UIImage</code> from custom text in <code>Swift3</code>.</p>
  
  <p>Using <code>iOS Controls</code>, It's possible to create an UIImage, below is the code:</p>
  
  <pre><code>class func imageWithText(txtField: UITextField) -&gt; UIImage {
          UIGraphicsBeginImageContextWithOptions(txtField.bounds.size, false, 0.0)
          txtField.layer.render(in: UIGraphicsGetCurrentContext()!)
          let img = UIGraphicsGetImageFromCurrentImageContext()
          UIGraphicsEndImageContext()
          return img!
      }
  </code></pre>
  
  <p>Note: I know it's also possible to add some text to an image, but I don't want to do like this. </p>
  
  <p>Can someone help me to resolve this? Thank you!</p>