Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. @IBDesignable extension UIView {
  2.  
  3. /* The color of the shadow. Defaults to opaque black. Colors created
  4. * from patterns are currently NOT supported. Animatable. */
  5. @IBInspectable var shadowColor: UIColor? {
  6. set {
  7. layer.shadowColor = newValue!.cgColor
  8. }
  9. get {
  10. if let color = layer.shadowColor {
  11. return UIColor(cgColor:color)
  12. }
  13. else {
  14. return nil
  15. }
  16. }
  17. }
  18.  
  19. /* The opacity of the shadow. Defaults to 0. Specifying a value outside the
  20. * [0,1] range will give undefined results. Animatable. */
  21. @IBInspectable var shadowOpacity: Float {
  22. set {
  23. layer.shadowOpacity = newValue
  24. }
  25. get {
  26. return layer.shadowOpacity
  27. }
  28. }
  29.  
  30. /* The shadow offset. Defaults to (0, -3). Animatable. */
  31. @IBInspectable var shadowOffset: CGPoint {
  32. set {
  33. layer.shadowOffset = CGSize(width: newValue.x, height: newValue.y)
  34. }
  35. get {
  36. return CGPoint(x: layer.shadowOffset.width, y:layer.shadowOffset.height)
  37. }
  38. }
  39.  
  40. /* The blur radius used to create the shadow. Defaults to 3. Animatable. */
  41. @IBInspectable var shadowRadius: CGFloat {
  42. set {
  43. layer.shadowRadius = newValue
  44. }
  45. get {
  46. return layer.shadowRadius
  47. }
  48. }
  49.  
  50. func addDropShadowToView() {
  51. layer.masksToBounds = false
  52. layer.shadowColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.25).cgColor
  53. layer.shadowOffset = CGSize(width: 2.5, height: 3.3)
  54. layer.shadowRadius = 3.3
  55. layer.shadowOpacity = 1.0
  56. }
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement