shadow rendering incorrectly? Swift

Viewed 63

I have a simple shadow code, and I wonder why the shadow looks like moved to the left side. I also attach an image of that issue image shadow

I'm pretty sure that shouldn't issue with offset because the width offset is equal to zero. Any ideas on how I can solve it? Thanks!

self.layer.shadowColor = UIColor.init(hexFromString: "000000").cgColor
self.layer.shadowPath = UIBezierPath(rect: self.bounds).cgPath
self.layer.rasterizationScale = UIScreen.main.scale
self.layer.shouldRasterize = true
self.layer.shadowOpacity = 0.1
self.layer.shadowOffset = CGSize(width: 0, height: offSetHeight)
self.layer.shadowRadius = 1
self.layer.masksToBounds = false
1 Answers

Once you give the shadow radius, the shadow will render to all the directions and not in a single direction. if you want to remove the shadow from the any of the single direction you can achieve it buy emebed it in another view with clips to bounds set true.

Related