title: Rounding and adding a border to a UIImage - Not UIImageView
body: <p>I have an extension that rounds the corners of a UIImage. This extension works great. I'd also like to add a stroke/border to the image.</p>
  
  <p>The reason I'm not doing all of this on a UIImageView is because the scaling/aspect ratio of the images changes, so it needs to round &amp; stroke the image, and not the imageView itself.</p>
  
  <pre><code>extension UIImage{
      var roundedImage: UIImage {
          let rect = CGRect(origin:CGPoint(x: 0, y: 0), size: self.size)
  
          let border = CAShapeLayer()
          border.path = CGPath(rect: rect, transform: nil)
          border.lineWidth = 10
          border.strokeColor = UIColor.red.cgColor
  
  
          UIGraphicsBeginImageContextWithOptions(self.size, false, 1)
          UIBezierPath(
              roundedRect: rect,
              cornerRadius: 40
              ).addClip()
          self.draw(in: rect)
          return UIGraphicsGetImageFromCurrentImageContext()!
      }
  }
  </code></pre>
  
  <p>I made progress by adding the <code>CAShapeLayer()</code> to add the red stroke. Just can't figure out how to add it to the actual path of <code>roundedImage</code>. Or if this is even the right approach. </p>
  
  <p><strong>How can I create a UIImage extension to both round the corners and add a border/stroke?</strong></p>