W3Schools Learner's Blog

w3Schools programming knowledge summary website

div

12/07/2017

How to add a shadow to a UIView?

This tutorial to learn how to add the shadow on UIView. There are four properties of shadow which is config on UIView.
Shadow effect
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.

This is swift 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)

No comments:

Post a Comment

Note: only a member of this blog may post a comment.