title: Swift Image masking
body: <p>Trying to achieve something like below picture. Where the image has a mask to display certain portion of the image. Here is the code to create the shape</p>
  
  <pre><code>let shape = CAShapeLayer()       
  shape.opacity = 0.5
  shape.lineWidth = 2
  shape.lineJoin = kCALineJoinMiter        
  
  let path = UIBezierPath()
  path.moveToPoint(CGPointMake(0 , 0))
  path.addLineToPoint(CGPointMake(200, 0))
  path.addLineToPoint(CGPointMake(160, 200))
  path.addLineToPoint(CGPointMake(0, 200))
  path.closePath()
  shape.path = path.CGPath
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/RVINH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RVINH.png" alt="enter image description here"></a></p>
  
  <p>Is there a way to add image into this layer. so its bound are set respective to the shape? BEFORE/AFTER image can be ignored. </p>
  
  <p>Any leads would be appreciated. Thanks!</p>