Anita
Anita

Reputation: 39

Adding a shadow to a view with rounded corners

This is the code for corners:

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

Please help me with the shadow code as well.

Upvotes: 1

Views: 77

Answers (1)

Abizern
Abizern

Reputation: 150605

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

Upvotes: 3

Related Questions