Skip to content

Instantly share code, notes, and snippets.

@fmaxx
Last active October 5, 2018 05:59
Show Gist options
  • Save fmaxx/d800f6060e04f8745b451ffbb8c65b89 to your computer and use it in GitHub Desktop.
Save fmaxx/d800f6060e04f8745b451ffbb8c65b89 to your computer and use it in GitHub Desktop.
UIView, shadow
// dropsahdow
extension UIView{
func dropShadow(shadowColor: UIColor = UIColor.black,
fillColor: UIColor = UIColor.white,
opacity: Float = 0.2,
offset: CGSize = CGSize(width: 0.0, height: 1.0),
radius: CGFloat = 10) -> CAShapeLayer {
let shadowLayer = CAShapeLayer()
shadowLayer.path = UIBezierPath(roundedRect: self.bounds, cornerRadius: radius).cgPath
shadowLayer.fillColor = fillColor.cgColor
shadowLayer.shadowColor = shadowColor.cgColor
shadowLayer.shadowPath = shadowLayer.path
shadowLayer.shadowOffset = offset
shadowLayer.shadowOpacity = opacity
shadowLayer.shadowRadius = radius
layer.insertSublayer(shadowLayer, at: 0)
return shadowLayer
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment