Group Group Group Group Group Group Group Group Group

Gradient Shadow How To?

Has anyone implemented a gradient shadow for a view (same as that of the gradience in the view)? I am looking into adding a CAGradientLayer as a sublayer and adding some filter or alike - no progress yet

I am able to apply a non-gradient shadow via something of this sort

func applyPremiumShadow(color: UIColor = .orange,
             alpha: Float = 1,
             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
  }
 }
1 Like

Hi @lganti,
Can you post some of the code where you are applying the shadow, because the code is not doing much at this point of time, so not sure what is the problem you are facing.

cheers,

1 Like

Hi,
Did you able to create this shadow? I’m struggling with this right now and so far no progress

It’s been a while and it was too time consuming to carry on but if you have not come across this -> https://stackoverflow.com/questions/45253036/swift-ui-button-shadow-gradient; might be useful

This topic was automatically closed after 166 days. New replies are no longer allowed.