Search code examples
iosswiftuiswiftui-sheet

How to change background color of bottom sheet?


I cannot use a ZStack to fill the color because by content inside a bottom sheet is a searchable view. Hence the header is showing the color of the sheet. Is there a way to change the color using UIKit or SwiftUI (preferably)?

.sheet(isPresented: $viewModel.isPresented) {
    ZStack {
        Color(.black)
            .ignoresSafeArea()
        NavigationStack {
            SearchableView()
        }
    }
})

Update: -

  1. Tried using .presentationBackground(.blue) and it changes the background of the content but the header is still the original color with the search bar

enter image description here


Solution

  • Turns out it was the toolbarBackground that was showing, hiding it within the navigation stack and then using @Benzy Neez's solution of using presentationBackground(.black) sets the background of the entire sheet without using a ZStack.

    .sheet(isPresented: $viewModel.isPresented) {
                NavigationStack {
                    AllEventsView(viewModel: viewModel, isMapView: true)
                        .toolbarBackground(.hidden)
                }
                .presentationBackground(.black)
    }