title: Convert UIView to UIImage Swift 3
body: <p>I am working on an extension to convert <code>UIView</code> to <code>UIImage</code> but I am having facing a strange issue that I am able to get correct image in iOS Simulator but I am getting black image in real device. Below is my code</p>
  
  <pre><code>extension UIView {
  func screenshotImage() -&gt; UIImage {
      UIGraphicsBeginImageContextWithOptions(self.bounds.size, false, 0.0);
      self.drawHierarchy(in: self.bounds, afterScreenUpdates: true)
      let screenShot = UIGraphicsGetImageFromCurrentImageContext();
      UIGraphicsEndImageContext();
      return screenShot!
  }
  }
  </code></pre>
  
  <p>Can anyone explain what am I doing wrong that I am not able to get correct image in real device?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Observations:</p>
  
  <p>Whenever I pass a UIView to this extension in simulator I get perfect image of that view</p>
  
  <p>Whenever I pass a UIView to this extension in real device I get an image which is completely black instead of elements in that UIView unlike to simulator result.</p>