SWIFT PROGRAMMING

How to Create Advanced Shadows in Swift — iOS Swift Guide

5 ways to create beautiful shadows for your apps

Baptiste Montagliani
The Startup
Published in
6 min readJun 6, 2020

--

Thanks to CoreAnimation and CALayer, we can easily apply to any UIView objects a custom shadow effect, through its layer property.

In this article we’ll see how to create 5 well known types of shadows:

  • Drop Shadows
  • Basic Contact Shadows
  • Contact Shadows with Depth
  • Flat Contact Shadows
  • Curved Shadows

But first, let’s see the 5 properties of the layer that we will use to create cutomized shadows.

shadowColor

Customize the color of the shadow. Default color is UIColor.black.cgColor, which make a dark shadow, but you can also set a light color to create a glow effect, or any other color.

shadowOpacity

Customize opacity of the shadow, between 0 and 1. A value of 0 means the shadow will not be visible.

shadowRadius

Customize the blur level of the shadow. A value of 0 means the shadow will not be blurred at all, it will be entirely flat.

--

--