0

I created a sketch design with shadows but when i tried implementing this in Xcode with swift i am not getting my desired result this is what i want to achieve

enter image description here

But this is what i keep getting

enter image description here

Here is the code i am using

extension CALayer {
func applySketchShadow(
    color: UIColor = .black,
    alpha: Float = 0.5,
    x: CGFloat = 0,
    y: CGFloat = 2,
    blur: CGFloat = 4,
    spread: CGFloat = 0)
{
    shadowColor = color.cgColor
    shadowOpacity = alpha
    shadowOffset = CGSize(width: x, height: y)
    shadowRadius = blur / 2.0
    if spread == 0 {
        shadowPath = nil
    } else {
        let dx = -spread
        let rect = bounds.insetBy(dx: dx, dy: dx)
        shadowPath = UIBezierPath(rect: rect).cgPath
    }
}
}
Sagaya Abdul
  • 151
  • 1
  • 11
  • Have you taken a look at this: https://stackoverflow.com/questions/15704163/draw-shadow-only-from-3-sides-of-uiview – Zyntx May 07 '18 at 00:18
  • Possible duplicate of [How to control shadow spread and blur?](https://stackoverflow.com/questions/34269399/how-to-control-shadow-spread-and-blur) – Quoc Nguyen May 07 '18 at 01:18

1 Answers1

-1

You only need to do is that you have to increase the value of y.

If you set the value of x and y to 0.0, then it will show the shadow like box. So, when you increase the value of y then the shadow will move to down side. So, you will not see the shadow upside and it looks like what you need.

Hope this will help you.

Khushbu
  • 2,342
  • 15
  • 18