Peter Lapisu
Peter Lapisu

Reputation: 21005

SwiftUI macOS search suggestion incorrected dark mode - don't follow the app preferredColorScheme

I have my system set to Dark Mode, but the app is light mode only, which works fine, having the main content view

.preferredColorScheme(.light)

however the search suggestions doesn't respect that

var body: some Scene {
    WindowGroup {
        ContentView()
        .preferredColorScheme(.light)
        .toolbar {
            ToolbarItemGroup(placement: .navigation) {
                Button(action: {
                }, label: {
                    Image(systemName: "chevron.left")
                })
                Button(action: {
                }, label: {
                    Image(systemName: "chevron.right")
                })
            }
        }
        .searchable(text: $searchText, placement: .toolbar) {
            Text("Font family A").searchCompletion("Hello")
            Text("Font family B").searchCompletion("HelloX")
        }
    }
    .windowToolbarStyle(.unified(showsTitle: false))
    
}

enter image description here

How to make the search suggestion follow the preferredColorScheme

Upvotes: 1

Views: 173

Answers (1)

Peter Lapisu
Peter Lapisu

Reputation: 21005

NSApp.appearance = NSAppearance(named: .aqua)

did work

reference: https://developer.apple.com/documentation/appkit/nsappearancecustomization/choosing_a_specific_appearance_for_your_macos_app

var body: some Scene {
    WindowGroup {
        ContentView()
        .onAppear(perform: {
            NSApp.appearance = NSAppearance(named: .aqua)
        }

Upvotes: 2

Related Questions