Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set UIHostingController's background color to clear?

I need to be able to see through my SwiftUI Views as well as the UIHosting Controller presenting them in order to see a background image underneath them. The code below still shows a white rectangle under my SwiftUI View. Paul Hudson says to use edgesIgnoringSafeArea but I cannot use that as my SwiftUIView is embedded in a larger UI scheme. Is there any way to make this white rectangle I am seeing clear?

    var body: some View {
          ZStack {
            VStack {
                 //omitted
              }
        }.background(Color.clear)
   }
like image 836
GarySabo Avatar asked Sep 15 '25 20:09

GarySabo


1 Answers

If you are using a UIHostingController, you need to set the backgroundColor property of its view to .clear as well.

yourHostingController.view.backgroundColor = .clear
like image 178
Dávid Pásztor Avatar answered Sep 17 '25 12:09

Dávid Pásztor