Changing bounds of a SwiftUI View when inserting UIKit functionality

139 views Asked by At

I am currently trying to insert UIKit functionality into SwiftUI as the API I am using has a tutorial with UIKit and my project is SwiftUI. For context, this is the exact post I used to implement this functionality: Inserting UIKit content into a SwiftUI view hierarchy

As a result, I have 2 different files: PBViewController and PassbaseView. The preview of PassbaseView looks like so: preview

As a result, calling PassBaseView() in the SwiftUI View where I desire to have the button doesn't result in what I want, as the whitespace around the button is included, when I just want the button. How do I only get the button to be inserted when I call PassBaseView()? My code is exactly the same as the post I linked.

My initial idea was to do this in the PBViewController file:

self.view.frame.size.width = 300
self.view.frame.size.height = 60

but this did not work.

1

There are 1 answers

0
Jacob F On BEST ANSWER

Adding the PassBaseView() into an additional VStack gets the desired functionality.