0

Good afternoon,

How do i achieve something like this in swift 3?

circle with blurred drop shadow beneath

The center of the shadow is about 30px from the bottom of the circle. I have tried using the shadow trick but i wasn't able to squish the shadow. I also tried using a picture from photoshop but the blur becomes nasty when scaled up.

el_beast
  • 89
  • 6
  • 3
    Possible duplicate of [Drop shadow in ios](https://stackoverflow.com/questions/40155443/drop-shadow-in-ios) – Tarvo Mäesepp Aug 03 '17 at 16:39
  • 1
    I would suggest (1. finding) or (2. creating) an image of an ellipse with a Gaussian blur effect applied to it and putting it in a UIImageView underneath the circle/whatever. 1) Just google ellipse Gaussian blur png. 2) Use a different program other than Photoshop to create the image such as affinity designer/gimp/illustrator/bunch of other programs. Then adjust the alpha value as needed. – Cobie Fisher Aug 03 '17 at 17:26
  • @Tarvo Your duplicate helped answer the question – el_beast Aug 07 '17 at 16:06

1 Answers1

0
let rect = CGRect(x: 0, y: midView.frame.minY, width: (midView.bounds.width), height: 20.0)

let elipticalPath = UIBezierPath(ovalIn: rect).cgPath
let maskLayer = CAGradientLayer()
maskLayer.frame = midView.bounds
maskLayer.shadowRadius = 15

maskLayer.shadowPath = elipticalPath
maskLayer.shadowOpacity = 0.7
maskLayer.shadowOffset = CGSize.zero
maskLayer.shadowColor = UIColor.gray.cgColor
midView.layer.addSublayer(maskLayer)
snjmhj
  • 1,001
  • 11
  • 21