Set Shadow on Bottom UIView only Set Shadow on Bottom UIView only ios ios

Set Shadow on Bottom UIView only


I think the proper way of thinking of shadow is, the shadow belongs to the object, which is the button, the uiview, not just part of the side. Imagining there is a virtual light source. You can't really just create a shadow for one side.

With that being said, the shadow will always be the shadow of the view as a whole. However, you can change the shadow offset to make it towards to the bottom.

view.layer.shadowOffset = CGSize(width: 0, height: 3)

This means you want the light source shoot the light from top to make the shadow to the bottom. The reason you still see some shadow at the top is the shadow radius. which is to simulate the diffuse of the light. The more diffuse the light is, the softer the shadow will be so you will see top shadow still.

view.layer.shadowRadius = 1 or 0.5

try to reduce the radius also. it will give you a better visual result.

To understand umbra, penumbra and antumbra if you need, check out https://en.wikipedia.org/wiki/Umbra,_penumbra_and_antumbra


This code working for swift 4 and shadow applying for view Bottom:

view.layer.masksToBounds = falseview.layer.shadowRadius = 4view.layer.shadowOpacity = 1view.layer.shadowColor = UIColor.gray.cgColorview.layer.shadowOffset = CGSize(width: 0 , height:2)


Change your shadowOffset

 view.layer.shadowOffset = CGSize(width: 0, height: 3)