6

Goal is to make a translucent sidebar on Mac Catalyst.

The code bellow gives a not translucent sidebar (image 1).

On Mac (not catalyst) the sidebar looks fine (image 2).

is it possible to have a translucent sidebar on Mac Catalyst?

enter image description here

enter image description here

import SwiftUI

struct ContentView: View {
    var body: some View {
        
        NavigationView {
            
            //sidebar
            List {
                Label("Books", systemImage: "book.closed")
                Label("Tutorials", systemImage: "list.bullet.rectangle")
         
            }
            .background(Color.clear)

            .listStyle(SidebarListStyle())
            
            //content
            Text("Sidebar")
            .navigationTitle("Sidebar")
        }
        
        
    }
}
pawello2222
  • 46,897
  • 22
  • 145
  • 209
Mane Manero
  • 3,086
  • 5
  • 25
  • 47

3 Answers3

3

You should select "Optimize Interface for Mac" in your target's General settings tab. Then the sidebar will be translucent.

BlueSky335
  • 31
  • 4
1

Start with the AppDelegate main and follow Apple's tutorial re: UISplitViewController "Apply a Translucent Background to Your Primary View Controller".

https://developer.apple.com/documentation/uikit/mac_catalyst/optimizing_your_ipad_app_for_mac

In wrapping UISplitViewController in a UIViewControllerRepresentable, I wasn't able to get translucency, but did get full-height sidebar.

Ryan
  • 1,252
  • 6
  • 15
0

I figured out that using .background(Color.clear) on sidebar View makes possible translucent background even if ListStyle is not specified as SidebarListStyle(). Works in Xcode 13.1 for me

struct ContentView: View {
    var body: some View {
        NavigationView { // without wrapping to NavigationView it won't work
            List { // can be VStack or HStack
                Text("Hello, world!")
                  .padding()
            }
            .listStyle(SidebarListStyle()) // works with other styles
        Text("")
    }
  }
}

struct YourApp: App {
   var body: some Scene {
      WindowGroup {
        ContentView()
            .toolbar {
                Button {
                    
                } label: {
                    Image(systemName: "gear")
                }

            }
            .background(Color.clear) // 3 <-- MUST HAVE!
      }
   }
}