UITableCell's border clips shadow of its image content
<p>I am trying to add shadow to an <code>UIImage</code> that is inside a <code>UITableViewCell</code>. I configured image using <code>UIBezierPath</code> to draw a shadow around its <code>bounds</code>. The shadow appear on either side of the image but the shadow on the top of image is clipped by the table view cell's border because there is no space between image's top and the table cell's border. I cannot have space between image's top and border because these cells are collapsible and will clip lower parts of the image to make it look like a carousel of cards stacked one on the top of another. Here is the code I am using to generate shadows:</p>

<pre><code>let shadowPath = UIBezierPath(rect: self.bounds)
layer.masksToBounds = false
self.clipsToBounds = false
layer.shadowColor = UIColor.blackColor().CGColor
layer.shadowOffset = CGSizeMake(0.0, -3.0)
layer.shadowOpacity = 0.1
layer.shadowRadius = 0.56
layer.shadowPath = shadowPath.CGPath
</code></pre>

<p>Here is a screenshot of what I'm trying to achieve:
<a href="https://i.stack.imgur.com/DsrSP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DsrSP.png" alt="Carousel view of the cards"></a></p>

<p>What I've done so far is dynamically load table cells with images of cards, hide overflow of image that are greater than the height of the cells, increase height of cells on tap so that the tapped card pushes other cards below it by increasing the height of the cell and come to full view mode.</p>

<p>The problem is the shadows on top of the card gets hidden because maybe it tresspasses into the cell above it?</p>

<p>I understand that my entire approach might be wrong on this one, so I'm open to any suggestions. Please help.</p>

<p><strong>UPDATE</strong></p>

<p><a href="https://github.com/gleue/TGLStackedViewController" rel="nofollow noreferrer">https://github.com/gleue/TGLStackedViewController</a> -> TGLStackedViewController</p>

<p>This view controller is exactly what I want plus shadows on top. Now I've come to realize that I do not need to render shadows while viewing but adding shadows while saving image will do. It is more efficient as well because the app does not have to draw the shadows every time the image is being displayed The problem however, is, this library is written in ObjC and is compatible with iOS9+ only.</p>