Skip to content

Instantly share code, notes, and snippets.

@maxcampolo
Created August 29, 2016 16:39
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxcampolo/f893ae8c323b918ce1749390df818503 to your computer and use it in GitHub Desktop.
Save maxcampolo/f893ae8c323b918ce1749390df818503 to your computer and use it in GitHub Desktop.
Extension to add a shadow to a UIView
extension UIView {
/**
Set a shadow on a UIView.
- parameters:
- color: Shadow color, defaults to black
- opacity: Shadow opacity, defaults to 1.0
- offset: Shadow offset, defaults to zero
- radius: Shadow radius, defaults to 0
- viewCornerRadius: If the UIView has a corner radius this must be set to match
*/
func setShadowWithColor(color: UIColor?, opacity: Float?, offset: CGSize?, radius: CGFloat, viewCornerRadius: CGFloat?) {
//layer.shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: viewCornerRadius ?? 0.0).CGPath
layer.shadowColor = color?.CGColor ?? UIColor.blackColor().CGColor
layer.shadowOpacity = opacity ?? 1.0
layer.shadowOffset = offset ?? CGSize.zero
layer.shadowRadius = radius ?? 0
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment