I do not understand how to remove a shadow that was added to a view.
I add to my view in initWithFrame
a shadow in this way:
self.layer.borderWidth
I tried the other answers, the only thing that worked for me was to toggle layer.masksToBounds
to true/false
lazy var myView: UIView = {
let view = UIView()
view.translatesAutoresizingMaskIntoConstraints = false
view.backgroundColor = .white
view.layer.cornerRadius = 5
view.layer.shadowColor = UIColor.black.cgColor
view.layer.shadowOpacity = 3
view.layer.shadowOffset = .zero
view.layer.shadowRadius = 5
return view
}()
func showShadow() {
myView.layer.masksToBounds = false
}
func hideShadow() {
myView.layer.masksToBounds = true
}