title: Inner shadow in UITextField with rounded corners
body: <p>I want to implement this <code>UITextField</code> design: </p>
  
  <p><a href="https://i.stack.imgur.com/9qjpU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9qjpU.png" alt="enter image description here"></a></p>
  
  <p>In Zeplin here is the properties of the shadow:</p>
  
  <p><a href="https://i.stack.imgur.com/mqdel.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mqdel.png" alt="enter image description here"></a></p>
  
  <p>What I have tried ? </p>
  
  <pre><code>override func layoutSubviews() {
      super.layoutSubviews()
      self.layer.cornerRadius = self.frame.size.height/2
      self.addInnerShadow()
  }
  
  
  private func addInnerShadow() {
      let innerShadow = CALayer()
      innerShadow.frame = bounds
      // 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.black.cgColor
      innerShadow.shadowOffset = CGSize(width: 0, height: 3)
      innerShadow.shadowOpacity = 0.05
      innerShadow.shadowRadius = 3
      innerShadow.cornerRadius = self.frame.size.height/2
      layer.addSublayer(innerShadow)
  }
  </code></pre>
  
  <p>result:</p>
  
  <p><a href="https://i.stack.imgur.com/88VOi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/88VOi.png" alt="enter image description here"></a></p>
  
  <p>Update: </p>
  
  <pre><code>override func layoutSubviews() {
       super.layoutSubviews()
       self.layer.cornerRadius = self.frame.size.height/2
       self.addInnerShadow()
   }
  
  
  private func addInnerShadow() {
      let innerShadow = CALayer()
      innerShadow.frame = bounds
      // Shadow path (1pt ring around bounds)
      let path = UIBezierPath(roundedRect: innerShadow.bounds.insetBy(dx: -1, dy: -1), cornerRadius: self.frame.size.height/2)
      let cutout = UIBezierPath(rect: innerShadow.bounds).reversing()
      path.append(cutout)
      innerShadow.shadowPath = path.cgPath
      innerShadow.masksToBounds = true
      // Shadow properties
      innerShadow.shadowColor = UIColor.black.cgColor
      innerShadow.shadowOffset = CGSize(width: 0, height: 3)
      innerShadow.shadowOpacity = 0.05
      innerShadow.shadowRadius = 3
      //innerShadow.cornerRadius = self.frame.size.height/2
      layer.addSublayer(innerShadow)
  }
  </code></pre>
  
  <p>result:</p>
  
  <p><a href="https://i.stack.imgur.com/gtw5i.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gtw5i.png" alt="enter image description here"></a></p>
  
  <p>the corner radius is causing a problem because the path is still rectangular and the shadow looks different  </p>