我在我的应用程序中添加了一个按钮,并将其设置为以下代码:
locationButton.layer.cornerRadius = 7
locationButton.clipsToBounds = true
locationButton.layer.shadowColor = UIColor.black.cgColor
locationButton.layer.shadowOffset = CGSize(width: 0, height: 3)
locationButton.layer.shadowRadius = 3
locationButton.layer.shadowOpacity = 1
locationButton.layer.masksToBounds = true
我也做了同样的事情
profileView.layer.shadowColor = UIColor.black.cgColor
profileView.layer.shadowOffset = CGSize(width: 0, height: 5)
profileView.layer.shadowRadius = 10
profileView.layer.shadowOpacity = 0.5
profileView.layer.masksToBounds = true
按钮显示时完全没有阴影,而视图的阴影不是围绕边框而是围绕其内部的元素。
最佳答案
这是工作代码
button.layer.masksToBounds = false
button.layer.shadowColor = UIColor.red.cgColor
button.layer.shadowOffset = CGSize(width: 5, height: 5)
button.layer.shadowOpacity = 1
button.layer.borderWidth = 1