[英]Change the tab selection color in TabBar SwiftUI
I am trying to change the color of selected tab in TabBar, but nothing worked. 我试图在TabBar中更改所选选项卡的颜色,但没有任何效果。 I can change the TabBar
backgroundColor
by writing 我可以通过编写来改变TabBar
backgroundColor
struct ContentView: View {
init() {
UITabBar.appearance().backgroundColor = UIColor.purple
}
var body: some View {
}
}
In swift, we set tintColor
and it does change the color of selected tab. 在swift中,我们设置了
tintColor
,它确实改变了所选标签的颜色。 But what do i need to do for swiftUI? 但是我需要为swiftUI做些什么呢?
Here is my code, 这是我的代码,
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)
}
Any help?? 任何帮助? Thanks!!
谢谢!!
Use accentColor
: https://developer.apple.com/documentation/swiftui/tabview/3368073-accentcolor 使用
accentColor
: https : //developer.apple.com/documentation/swiftui/tabview/3368073-accentcolor
TabView {
// fill this out with your tabbed content
}
.accentColor(.orange)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.