gpt4 book ai didi

SwiftUI:如何更改 NavigationView.toolbar 背景颜色

转载 作者:行者123 更新时间:2023-12-04 00:53:27 25 4
gpt4 key购买 nike

关于如何将特定背景颜色应用于底部工具栏的任何想法?

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 测试。
demo

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com