just like this
and my view is simply:
Text("Testing Widget")
and tried this:
VStack {
Text("Testing Widget")
}
.background(Color(UIColor.clear))
and nothing happend:(.
Just came across a solution for me!
You have to set the backgroundColor of the UIHostingController's view to .clear, and then it will work. You don't need to set the background color of the SwiftUI view.
let hostingController = UIHostingController(rootView: SwiftUIView())
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
view.addSubview(hostingController.view)
addChild(hostingController)
hostingController.didMove(toParent: self)
// You may want to add constraints
hostingController.view.backgroundColor = .clear // <- IMPORTANT
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With