我有一个小型 SwiftUI 项目。单击选项卡栏一时,我想将选项卡栏背景颜色更改为黑色,单击零选项卡栏项目时,我想将背景颜色更改为白色。任何想法?
截屏:
内容视图:
struct ContentView: View {
init() {
UITabBar.appearance().barTintColor = .systemBackground
UITabBar.appearance().unselectedItemTintColor = UIColor(named: "TabBarUnselected")
}
var body: some View {
TabView {
Text("Zero")
.tabItem {
Label("Zero", systemImage: "0.square.fill")
}
Text("One")
.tabItem {
Label("One", systemImage: "1.square.fill")
}
}
.accentColor(Color("TabBarTint"))
}
}