ios - SwiftUI - 如何仅在顶部显示阴影?

标签 ios swift swiftui

我正在尝试为我的 VStack 提供阴影(仅在顶部),但是当我喜欢下面的阴影时,所有方面都可以看到,例如按钮、文本。但我试图只为容器提供边框。

.background(Color.white // any non-transparent background
               .shadow(color: Color.red, radius: 10, x: 0, y: 0)
             )
我想要像下面这样的用户界面
enter image description here
谢谢你的帮助

最佳答案

尝试使用 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!
)
结果:
Red shadow only on top

关于ios - SwiftUI - 如何仅在顶部显示阴影?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68765679/

相关文章:

ios - 如何在 swiftUI 中使图像可点击?

SwiftUI 使用本地化为句子中的一个单词添加颜色

datepicker - 修复来自 DatePicker 的数百行警告重新布局约束

iOS 9 Spritekit 双击在 iPhone 6S 上不起作用

ios - PhoneGap iOS - 仅当照片大于 targetheight/targetwidth 时才调整相机大小

swift - 快速增加年份设置日历单位月份

ios - 将图像上传到 Firebase 并获取引用

iOS 谷歌原生广告不可点击

ios - 使用 AFNetWorking 发送请求时遇到问题

ios - Swift:Firestore 子集合、自定义对象和监听器