How to add a shadow to a UIView?

This tutorial to learn how to add the shadow on view. There are four properties of shadow which is config on view.




Shadow properties :

shadowColor : set the color of the shadow. Needed to the CGColor.

shadowOpacity: set the opacity 0 to 1 for transparent the shadow.

shadowOffset : its give the 3D offset effect of view.

shadowRadius : it's set for how wide the shadow should be.


Code :
let viewShadow = UIView(frame: CGRect(x: 0, y: 0, width: 120, height: 120))
viewShadow.center = self.view.center
viewShadow.backgroundColor = UIColor.yellow
viewShadow.layer.shadowColor = UIColor.red.cgColor
viewShadow.layer.shadowOpacity = 1
viewShadow.layer.shadowOffset = CGSize.zero
viewShadow.layer.shadowRadius = 5
self.view.addSubview(viewShadow)
Output :



Thanks
How to add a shadow to a UIView? How to add a shadow to a UIView? Reviewed by KIRIT MODI on 20:07:00 Rating: 5

No comments:

Powered by Blogger.