I am trying to add a shadow to my UIViews using a custom extension that I created for the UIView class. Here is the code for the extension:
extension UIView {
func round(_ radius : CGFloat = 10) {
layer.cornerRadius = radius
clipsToBounds = true
}
func addBorder(color: UIColor, width: CGFloat) {
layer.borderColor = color.cgColor
layer.borderWidth = width
}
func addShadow(opacity: Float, size: Double, radius: Double, color: UIColor ) {
layer.shadowColor = color.cgColor
layer.shadowOpacity = opacity
layer.shadowOffset = CGSize(width: size, height: size)
layer.shadowRadius = radius
layer.masksToBounds = true
}
}
The round and addBorder functions work perfectly fine, but the addShadow function does not seem to be working. I have tried calling the function on a UIView instance like this:
let myView = UIView()
myView.addShadow(opacity: 0.5, size: 2, radius: 4, color: .black)
But the shadow does not show up on the view
I have tested this extension with other types of views, such as buttons and labels, and the shadow works perfectly fine. It seems to be a problem only with UIViews.
Does anyone know what might be causing this issue? Any help would be greatly appreciated. Thank you in advance