Adding a shadow to a view with rounded corners

Viewed 54

This is the code for corners.

self.newView.layer.cornerRadius = 5.0
self.newView.layer.clipsToBound = true

Please help me with the shadow code as well

1 Answers

You do add a shadow layer in a similar way:

newView.layer.cornerRadius = 5
newView.backgroundColor = .blue
newView.clipsToBounds = true

// shadow
newView.layer.shadowColor = UIColor.black.cgColor
newView.layer.shadowOpacity = 0.5
newView.layer.shadowOffset = CGSize(width: 10, height: 10)
newView.layer.shadowRadius = 10
newView.layer.masksToBounds = false

enter image description here

Related