问题描述
我正在使用SwiftUI工作表模式运行iOS 13模拟器-尝试绘制工作表背景并忽略安全区域-但仍然显示白色工作表。有关如何正确执行此操作的任何想法?
var body: some View {
vstack(alignment: .center,spacing: 0) {
... redacted ...
} // vstack
.background(Color.gray.edgesIgnoringSafeArea(.all))
iPhone Simulator with sheet modal
查看图片(随附)
有什么想法我在做什么错吗?
解决方法
将顶部容器(在您的情况下为VStack
)扩展到整个工作表区域,例如
VStack {
// ... your content
}
.frame(maxWidth: .infinity,maxHeight: .infinity) // << here !!
.background(Color.gray.edgesIgnoringSafeArea(.all))
,
绘制背景的最佳方法是使用ZStack:
var body: some View {
ZStack {
// replace with the color you want
Color.green
.edgesIgnoringSafeArea(.all)
VStack {
// put view's Content here
}
}
}