Gradient Colour Shadow in UIView & UIButton with Radius

267 Views Asked by At

I have tried lots of things from SO, but I'm not able to make following type of gradient shadow.

Can anyone help to make like this?

Gradient Shadow

I have tried following code.

func addGradientShadowToMakeReservation() {
    
    let gradientLayer = CAGradientLayer()

    gradientLayer.colors = [
        UIColor(named: "GradiantColor1")!.cgColor,
        UIColor(named: "GradiantColor2")!.cgColor,
        UIColor(named: "GradiantColor2")!.cgColor
    ]

    gradientLayer.frame = CGRect(x: self.viewReservationGradiant.frame.minX - 40,
    y: self.viewReservationGradiant.frame.minY - 40,
    width: self.viewReservationGradiant.frame.width + 80,
    height: self.viewReservationGradiant.frame.height + 80)
    
    gradientLayer.masksToBounds = true
    
    let shadowLayer = CALayer()
    shadowLayer.frame = gradientLayer.bounds
    shadowLayer.shadowColor = UIColor.black.cgColor
    shadowLayer.shadowOpacity = 0.08
    shadowLayer.shadowRadius = 20
    shadowLayer.shadowPath = CGPath(rect: shadowLayer.bounds, transform: nil)
    
    gradientLayer.mask = shadowLayer
    
    self.viewReservationGradiant.clipsToBounds = false
    
    self.viewReservationGradiant.layer.addSublayer(gradientLayer)
}

But its didn't help me as expected.

0

There are 0 best solutions below