How to set UIHostingController's background color to clear?
Asked Answered
T

1

19

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)
   }
Tolle answered 19/8, 2020 at 17:24 Comment(0)
H
38

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

yourHostingController.view.backgroundColor = .clear
Heptangular answered 19/8, 2020 at 17:27 Comment(1)
Note that the calling for push view must be made with: view.modalPresentationStyle = .overFullScreen //for transparency support v.window?.rootViewController?.present(view, animated: true)Glengarry

© 2022 - 2024 — McMap. All rights reserved.