将拖放模糊阴影添加到圆圈

时间:2017-08-03 16:34:27

标签: ios iphone swift swift3

下午好,

我如何在swift 3中实现这样的目标?

circle with blurred drop shadow beneath

阴影的中心距圆圈底部约30px。我尝试过使用暗影技巧,但我无法挤压阴影。我也试过使用来自Photoshop的图片,但是当放大时模糊变得讨厌。

1 个答案:

答案 0 :(得分: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)