你应该使用
toolbarBackground
设置工具栏的颜色。
.toolbar {
ToolbarItemGroup(placement: .bottomBar) {
BottomBar()
}
}
.toolbarBackgroundVisibility(.visible, for: .bottomBar)
.toolbarBackground(.black, for: .bottomBar)
在iOS 18之前,
toolbarBackgroundVisibility
(令人困惑地)也被称为
工具栏背景
,所以你会写
.toolbarBackground(.visible, for: .bottomBar)
.
这意味着你不需要所有这些
GeometryReader
,
ZStack
,
Color.black
,以及其他事物
BottomBar
.
底部酒吧
可以是三个按钮——你甚至不需要
HStack
.
var body: some View {
YellowButton()
Spacer()
SubmitButton()
Spacer()
BlueButton()
}
如果您的目标是iOS 16之前的版本,请考虑使用
safeAreaInset
而不是
toolbar
.
GeometryReader { geo in
// ...
}
.safeAreaInset(edge: .bottom) {
BottomBar() // in this case BottomBar does need the Color.black and other things that makes it fill the whole width
}