I have created a custom UIView in my iOS project that has a drop shadow. My aim is to apply the same gradient to the shadow as it is on the view's background.
Below is an example of how my current solid colour shadows look.
This is done through a subclass of UIView with the below code:
override func layoutSubviews() {
let gradientLayer = layer as! CAGradientLayer
gradientLayer.colors = [topColor.cgColor, bottomColor.cgColor]
gradientLayer.startPoint = CGPoint(x: startPointX, y: startPointY)
gradientLayer.endPoint = CGPoint(x: endPointX, y: endPointY)
layer.cornerRadius = cornerRadius
layer.shadowColor = shadowColor.cgColor
layer.shadowOffset = CGSize(width: shadowX, height: shadowY)
layer.shadowRadius = shadowBlur
layer.shadowOpacity = 1
let inset: CGFloat = bounds.width * 0.05
layer.shadowPath = UIBezierPath(roundedRect: bounds.insetBy(dx: inset, dy: 0.0), cornerRadius: cornerRadius).cgPath
}
I have been playing around with creating a second gradient layer and masking it to the shadow but have had no luck. Please point me in the right direction!