I am trying to change the highlight color of the tabs in SwiftUI, but when I applied .tint() to the TabView (which is the root view of my app), the entire app seems to be affected. What's more, the views under each seems to randomly switch between the default blue tint and the custom tint I configured.
Is there a way to only change the tab bar's tint color? Thanks!
The only way to change the tab bar's tint color is the use the .tint
modifier as you mentioned. You're correct, it will change the entire app. You can override this further down the stack if you'd like. For instance, the following code snippet will set the tint color inside the second tab to be green, as shown in the edit button. The tab bar tint color will be red though.
struct ContentView: View {
var body: some View {
TabView {
Tab("Test", systemImage: "person.crop.circle") {
Text("Hello, world!")
}
Tab("List", systemImage: "rectangle") {
NavigationStack {
List {
Text("Test1")
}
.toolbar {
EditButton()
}
}
.tint(.green)
}
}
.tint(.red)
}
}
If you're seeing bugs with randomly changing colors though, I recommend filing a feedback report for sure.
Thanks!
Sydney