Guest User

Untitled

a guest
Jan 19th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. private var shadowLayer: CAShapeLayer!
  2. private var cornerRadius: CGFloat = 25.0
  3. private var fillColor: UIColor = .blue // the color applied to the shadowLayer, rather than the view's backgroundColor
  4.  
  5. override func layoutSubviews() {
  6. super.layoutSubviews()
  7.  
  8. if shadowLayer == nil {
  9. shadowLayer = CAShapeLayer()
  10.  
  11. shadowLayer.path = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath
  12. shadowLayer.fillColor = fillColor.cgColor
  13.  
  14. shadowLayer.shadowColor = UIColor.black.cgColor
  15. shadowLayer.shadowPath = shadowLayer.path
  16. shadowLayer.shadowOffset = CGSize(width: 0.0, height: 1.0)
  17. shadowLayer.shadowOpacity = 0.2
  18. shadowLayer.shadowRadius = 3
  19.  
  20. layer.insertSublayer(shadowLayer, at: 0)
  21. }
  22. }
Add Comment
Please, Sign In to add comment