我在我的应用程序中添加了一个按钮并使用以下代码进行设置:
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
我用UIView做了同样的事情
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
该按钮显示时根本没有阴影,而视图的阴影不在边框周围,而是在其内部的元素周围。