关于如何将特定背景颜色应用于底部工具栏的任何想法?
NavigationView {
List {
....
}
.toolbar {
ToolbarItem(placement: .bottomBar) {
Button(action: { model.selectTab(tab: "ITEM1") }, label: { Text("ITEM1") })
}
ToolbarItem(placement: .bottomBar) {
Button(action: { model.selectTab(tab: "ITEM2") }, label: { Text("ITEM2") })
}
ToolbarItem(placement: .bottomBar) {
Button(action: { model.selectTab(tab: "ITEM3") }, label: { Text("ITEM3") })
}
}
}
最佳答案
您可以使用 UIToolbar
执行此操作外貌。使用 Xcode 12/iOS 14 测试。
struct DemoView: View {
init() {
UIToolbar.appearance().barTintColor = UIColor.red
}
var body: some View {
NavigationView {
List {
Text("Item")
}
.toolbar {
ToolbarItem(placement: .bottomBar) {
Button(action: { }, label: {Text("ITEM1")})
}
ToolbarItem(placement: .bottomBar) {
Button(action: { }, label: {Text("ITEM2")})
}
ToolbarItem(placement: .bottomBar) {
Button(action: { }, label: {Text("ITEM3")})
}
}
}
}
}
关于SwiftUI:如何更改 NavigationView.toolbar 背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64583275/