如何将UIHostingController的背景颜色设置为透明?

15
我需要能够透过我的SwiftUI视图以及呈现它们的UIHosting Controller来看到它们下面的背景图片。以下代码仍然在我SwiftUI View下显示一个白色矩形。Paul Hudson在他的文章中建议使用edgesIgnoringSafeArea,但我无法这样做,因为我的SwiftUIView嵌入在更大的UI方案中。有没有办法使我看到的这个白色矩形变成透明的?
    var body: some View {
          ZStack {
            VStack {
                 //omitted
              }
        }.background(Color.clear)
   }
1个回答

30

如果您正在使用UIHostingController,您还需要将其viewbackgroundColor属性设置为.clear

yourHostingController.view.backgroundColor = .clear

2
请注意,必须使用以下方式调用push view:view.modalPresentationStyle = .overFullScreen //用于支持透明度 v.window?.rootViewController?.present(view, animated: true) - benchuk

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接