title: Swift Creating an Inner Shadow on a round UIView
body: <p>I'd really appreciate it, if someone could tell me why the code below does not give me the inner shadow, or give me a solution that will give an inner shadow.</p>
  
  <p>I need to create an inner shadow on a rounded UIView. I've been through many answers and found ways of getting this on a normal squared UIViews, but have found no solution that works on a rounded view. Instead I find solutions like the one shown below that look ok to me, but do not create the required inner shadow when I implement them.
  Here is my screen, it is the white view between the outer blue and inner yellow views that I want to add the shadow to: </p>
  
  <p><a href="https://i.stack.imgur.com/GqnaG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GqnaG.png" alt="outer"></a></p>
  
  <p>I have subclassed the view, here is my draw rect code:</p>
  
  <pre><code>let innerShadow = CALayer()
      // Shadow path (1pt ring around bounds)
      let path = UIBezierPath(rect: innerShadow.bounds.insetBy(dx: -1, dy: -1))
      let cutout = UIBezierPath(rect: innerShadow.bounds).reversing()
      path.append(cutout)
      innerShadow.shadowPath = path.cgPath
      innerShadow.masksToBounds = true
      // Shadow properties
      innerShadow.shadowColor = UIColor.darkGray.cgColor
      innerShadow.shadowOffset = CGSize(width: 0.0, height: 7.0)
      innerShadow.shadowOpacity = 1
      innerShadow.shadowRadius = 5
      // Add
      self.layer.addSublayer(innerShadow)
  
      // Make view round
      self.layer.cornerRadius = self.frame.size.width/2
      self.layer.masksToBounds = true
  </code></pre>
  
  <p>Many thanks for any help with this. Please do let me know if you have questions.</p>