Skip to content

Instantly share code, notes, and snippets.

@darrarski
Created January 30, 2019 22:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darrarski/e85136f59bbfb96452691cf3db971e19 to your computer and use it in GitHub Desktop.
Save darrarski/e85136f59bbfb96452691cf3db971e19 to your computer and use it in GitHub Desktop.
import UIKit
struct SketchShadow {
let color: UIColor?
let x: CGFloat
let y: CGFloat
let blur: CGFloat
let spread: CGFloat
}
extension CALayer {
func apply(_ shadow: SketchShadow) {
shadowColor = shadow.color?.cgColor
shadowOpacity = 1
shadowOffset = CGSize(width: shadow.x, height: shadow.y)
shadowRadius = shadow.blur / 2.0
if shadow.spread == 0 {
shadowPath = nil
} else {
let dx = -shadow.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