Add shadow to UIButton and UIView with the following parameters. I am able to set Opacity, Size, Distance but its not coming perfect. Can any one suggest how to add these. I have tried other solutions available on net but nothings works.
Angle: 90, Opacity 13% Distance 4px Spread: 10% Size: 9px
This is the kind of shadow I am getting when I try to apply the following code.
self.buttonCategory2.setShadowWithColor(color: UIColor.black, opacity: 0.13, offset: CGSize(width: 9, height: 9), radius: 4, viewCornerRadius: nil)
extension UIView {
/**
Set a shadow on a UIView.
- parameters:
- color: Shadow color, defaults to black
- opacity: Shadow opacity, defaults to 1.0
- offset: Shadow offset, defaults to zero
- radius: Shadow radius, defaults to 0
- viewCornerRadius: If the UIView has a corner radius this must be set to match
*/
func setShadowWithColor(color: UIColor?, opacity: Float?, offset: CGSize?, radius: CGFloat, viewCornerRadius: CGFloat?) {
//layer.shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: viewCornerRadius ?? 0.0).CGPath
layer.shadowColor = color?.cgColor ?? UIColor.black.cgColor
layer.shadowOpacity = opacity ?? 1.0
layer.shadowOffset = offset ?? CGSize.zero
layer.shadowRadius = radius
}
}
Required Shadow