简体   繁体   中英

SwiftUI: macOS Can't change TabView's tabItem accent color

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: 在此处输入图像描述

Running on macOS settings view: 在此处输入图像描述

Here's the system default settings: 在此处输入图像描述

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

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

演示

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM