我试图在TabBar中更改所选选项卡的颜色/uff0c但没有任何效果。 我可以通过编写来改变TabBar backgroundColor
struct ContentView: View {
init() {
UITabBar.appearance().backgroundColor = UIColor.purple
}
var body: some View {
}
}
在swift中/uff0c我们设置了tintColor/uff0c它确实改变了所选标签的颜色。 但是我需要为swiftUI做些什么呢/uff1f
这是我的代码/uff0c
TabView(selection: $selection) {
AView()
.tabItem {
VStack {
Image(systemName: "bubble.left.and.bubble.right")
Text("A Tab")
}
}.tag(0)
BView()
.tabItem {
VStack {
Image(systemName: "house")
Text("B Tab")
}
}.tag(1)
CView()
.tabItem {
VStack {
Image(systemName: "circle.grid.3x3")
Text("C Tab")
}
}.tag(2)
}
方法是/uff1a
使用 accentColor
: https://developer.apple.com/documentation/swiftui/tabview/3368073-accentcolor
TabView {
// fill this out with your tabbed content
}
.accentColor(.orange)