Add shadow to image in UIKit

Viewed 1042

I have this screen with an UIImageView (the image is a SF Symbol)

The user can see this icon clearly, white on black. But - if the background is different:

It may be hard to see it. I want to add a black shadow to the image so the user can see it better.

I tried looking online but all I saw is how to add shadow to the image view box, and that is not what I need. I need the shadow around the icon itself and not around the box of the image.

Any ideas? thanks in advance

1 Answers

Try this:

imageView.layer.shadowColor = UIColor.black.cgColor
imageView.layer.shadowRadius = 3.0
imageView.layer.shadowOpacity = 1.0
imageView.layer.shadowOffset = CGSize(width: 4, height: 4)
imageView.layer.masksToBounds = false
Related