我正在尝试为我的 VStack 提供阴影(仅在顶部),但是当我喜欢下面的阴影时,所有方面都可以看到,例如按钮、文本。但我试图只为容器提供边框。
.background(Color.white // any non-transparent background
.shadow(color: Color.red, radius: 10, x: 0, y: 0)
)
我想要像下面这样的用户界面谢谢你的帮助
最佳答案
尝试使用 mask(_:)
修饰符,如 this answer 所示.
.background(
Color.white // any non-transparent background
.shadow(color: Color.red, radius: 10, x: 0, y: 0)
.mask(Rectangle().padding(.top, -20)) /// here!
)
结果:关于ios - SwiftUI - 如何仅在顶部显示阴影?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68765679/