Home > Software engineering >  SwiftUI: macOS Can't change TabView's tabItem accent color
SwiftUI: macOS Can't change TabView's tabItem accent color

Time:07-02

TabView {
    Text("The First Tab")
        .badge(10)
        .tabItem {
            Image(systemName: "1.square.fill")
            Text("First")
        }
    Text("Another Tab")
        .tabItem {
            Image(systemName: "2.square.fill")
            Text("Second")
        }
    Text("The Last Tab")
        .tabItem {
            Image(systemName: "3.square.fill")
            Text("Third")
        }
}
.font(.headline)
.accentColor(.orange) // don't work on macOS

This codes works on iOS: enter image description here

Running on macOS settings view: enter image description here

Here's the system default settings: enter image description here

Test on macOS 12.4 (21F79) and iOS 15.4. can't change the default accent blue.

CodePudding user response:

On macOS it can be changed this way:

struct ContentView: View {
    init() {
        UserDefaults.standard.set(1, forKey: "AppleAccentColor")  // << here !!
    }
    var body: some View {
        TabView {

Tested with Xcode 13.4 / macOS 12.4

demo

*see for other values https://stackoverflow.com/a/51695756/12299030
**also some related https://stackoverflow.com/a/68846972/12299030

  • Related