title: Screenshot a view with label and transparent background in iOS and upload it to server
body: <p>I want to screenshot a view and create an UIImage from it. I want the transparency attribute of the view to be maintained in my image. I tried this method after creating an extension of UIImage but the background is not transparent in the resultant image when uploaded to the server.</p>
  
  <p>Kindly help or point me if I am doing something wrong!! This means that the resultant png was not having transparency.</p>
  
  <pre><code>class func createTransparentImageFrom(label: UILabel, imageSize: CGSize) -&gt; UIImage {
      UIGraphicsBeginImageContextWithOptions(imageSize, false, 2.0)
      let currentView = UIView.init(frame: CGRect(x: 0, y: 0, width: imageSize.width, height: imageSize.height))
      currentView.backgroundColor = UIColor.clear
      currentView.addSubview(label)
  
      currentView.layer.render(in: UIGraphicsGetCurrentContext()!)
      let img = UIGraphicsGetImageFromCurrentImageContext()
      UIGraphicsEndImageContext()
      return img!
  }
  </code></pre>