Created
March 26, 2019 05:49
-
-
Save AmatsuZero/6ff98030da66ddf570602ade20b24250 to your computer and use it in GitHub Desktop.
CALayer阴影
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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