title: How to render UIView to UIImage without rendering Navigation Bar, Toolbar, etc
body: <p>I've looked at several other Stack Overflow answers on how to do this. They work pretty well, and I've added my own line of code to save them to the camera roll. I've added my code at the bottom of this question.</p>
  
  <p>That code is inside of a custom UIView class attached to a UIView. The user draws an image inside of that UIView and saves it. However, when I use the save function, it saves the navigation bar and a bunch of other UIImages on the picture, and I don't want that. I only want it to save what's on that UIView, instead of the ENTIRE view.</p>
  
  <p>As I stated, here is the code: </p>
  
  <pre><code>func downloadImage() {
          UIGraphicsBeginImageContextWithOptions(self.bounds.size, self.isOpaque, 0.0)
          self.layer.render(in: UIGraphicsGetCurrentContext()!)
          let img = UIGraphicsGetImageFromCurrentImageContext()
          UIGraphicsEndImageContext()
  
          UIImageWriteToSavedPhotosAlbum(img!, nil, nil, nil)
      }
  </code></pre>
  
  <p>EDIT: I figured out why. In Interface Builder, all of the additional elements were as childs to the view I was saving my image from. Learn from my dumb mistakes and don't do that :)</p>