title: Round specific corners of and show shadow on specific sides only
body: <p>I have the following piece of code to round only specific corners of a view:</p>
  
  <pre><code>- (void)roundOnlySpecifiedCornersInView:(UIView *)view corners:(UIRectCorner)corners
  {
      UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners:(corners) cornerRadii:CGSizeMake(4.0, 4.0)];
      CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
  
      maskLayer.path  = maskPath.CGPath;
      view.layer.mask = maskLayer;
  }
  </code></pre>
  
  <p>This works perfectly in isolation. Now I also want shadow in my view, but I specifically want to apply shadow in different cases:</p>
  
  <ul>
  <li>on all sides</li>
  <li>all sides except bottom</li>
  <li>all sides except top</li>
  <li>left/right sides only</li>
  </ul>
  
  <p>All techniques I encountered work by creating an inset of the view. The problem with this, is that, say you want to only keep shadow on left/right sides, you offset bottom and top. Since the Rect is now less high, the shadow at the left and right does not cover the full height of the view. Also, the mask layer used for rounding corners causes the shadow to no longer appear.</p>
  
  <p>Example code for this:</p>
  
  <pre><code>    innerView.layer.shadowColor = [[UIColor colorWithWhite:0.0f alpha:0.1f] CGColor];
      innerView.layer.shadowOpacity = 1.0f;
      innerView.layer.shadowOffset = CGSizeMake(0.0f, 0.0f);
      innerView.layer.shadowRadius = 6.0f;
  
      CGRect shadowFrame = UIEdgeInsetsInsetRect(innerView.bounds, UIEdgeInsetsMake(9, 0, 9, 0));
      CGPathRef shadowPath = [UIBezierPath bezierPathWithRect:shadowFrame].CGPath;
  
      innerView.layer.shadowPath = shadowPath;
  </code></pre>
  
  <p>How can I round specific corners in a view and at the same time show shadow only at specified sides?</p>
  
  <p>Answers in Swift are appreciated too!</p>
  
  <p>Screenshot of what I want (this one is easy since all corners need to be rounded so I can use <code>.layer.cornerRadius</code> and it has shadow at all sides):
  <a href="https://i.stack.imgur.com/Ximkq.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Ximkq.png" alt="enter image description here"></a></p>
  
  <p>Now I just want to round only 2 of the corners (top left and top right, bottom left and bottom right) and add shadow to only some sides.</p>