14

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)
   }
GarySabo
  • 5,806
  • 5
  • 49
  • 124

1 Answers1

28

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

yourHostingController.view.backgroundColor = .clear
Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116
  • 2
    Note that the calling for push view must be made with: view.modalPresentationStyle = .overFullScreen //for transparency support v.window?.rootViewController?.present(view, animated: true) – benchuk May 19 '22 at 07:41