我尝试创建UIView(右,左,下)的阴影,但未创建确切的阴影。如何创建UIView的阴影(如下图所示)?请帮帮我!
答案 0 :(得分:0)
您可以使用UIBezierPath
向视图添加阴影,如下所示:
extension UIVIew{
func applyDropShadow(scale: Bool = true) {
layer.masksToBounds = false
layer.shadowColor = UIColor.black.cgColor
layer.shadowOpacity = 0.5
layer.shadowOffset = CGSize(width: -1, height: 1)
layer.shadowRadius = 1
layer.shadowPath = UIBezierPath(rect: bounds).cgPath
layer.shouldRasterize = true
layer.rasterizationScale = scale ? UIScreen.main.scale : 1
}
}
调整shadowOffset
以获得设计阴影位置。