Created
August 29, 2016 16:39
-
-
Save maxcampolo/f893ae8c323b918ce1749390df818503 to your computer and use it in GitHub Desktop.
Extension to add a shadow to a UIView
This file contains 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 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