Skip to content

Instantly share code, notes, and snippets.

@AmatsuZero
Created March 26, 2019 05:49
Show Gist options
  • Save AmatsuZero/6ff98030da66ddf570602ade20b24250 to your computer and use it in GitHub Desktop.
Save AmatsuZero/6ff98030da66ddf570602ade20b24250 to your computer and use it in GitHub Desktop.
CALayer阴影
extension CALayer {
func applySketchShadow(
color: UIColor = .black,
alpha: Float = 0.5,
x: CGFloat = 0,
y: CGFloat = 2,
blur: CGFloat = 4,
spread: CGFloat = 0)
{
shadowColor = color.cgColor
shadowOpacity = alpha
shadowOffset = CGSize(width: x, height: y)
shadowRadius = blur / 2.0
if spread == 0 {
shadowPath = nil
} else {
let dx = -spread
let rect = bounds.insetBy(dx: dx, dy: dx)
shadowPath = UIBezierPath(rect: rect).cgPath
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment