如何给带阴影的 UIView 赋予椭圆形

How to give oval shape to UIView with shadow

如何制作只有底部有阴影的椭圆形uiview

您需要为此使用 UIBezierPath。这是一个示例(只需要使用这些值):

   let layer = CAShapeLayer()
    layer.fillColor = UIColor.red.cgColor
    layer.shadowOffset = CGSize(width: 0, height: 2)
    layer.shadowRadius = 5
    layer.shadowColor = UIColor.black.cgColor
    layer.shadowOpacity = 0.5
    layer.shadowRadius = 2
    view.layer.addSublayer(layer)

    let path = UIBezierPath()
    path.move(to: .zero)
    path.addLine(to: CGPoint(x: view.frame.maxX, y: 0))
    path.addLine(to: CGPoint(x: view.frame.maxX, y: 50))
    path.addQuadCurve(to: CGPoint(x: 0, y: 50), controlPoint: CGPoint(x: view.frame.midX, y: 70))
    path.close()

    layer.path = path.cgPath

结果: