'Embeding UIKit view in SwiftUI

I'm currently trying to show a button inside my existing SwiftUI view, but it seems that the padding and constrains are working incorrectly.

The current UIView:

class PBViewController: UIViewController, PassbaseDelegate, ObservableObject {
    
    override func viewDidLoad() {
        
        super.viewDidLoad()
        PassbaseSDK.delegate = self
        let button = PassbaseButton(frame: CGRect(x: (self.view.frame.size.width - 240) / 2, y: 0, width: 240, height: 50))
        self.view.addSubview(button)
            
    }

    func onFinish(identityAccessKey: String) {
        print("onFinish with identityAccessKey \(identityAccessKey)")
        sessionstore.passbaseKeyEntry(key: identityAccessKey)
    }
    
    func onSubmitted(identityAccessKey: String) {
        print("onSubmitted with identityAccessKey \(identityAccessKey)")
        sessionstore.passbaseKeyEntry(key: identityAccessKey)
    }
    
    func onError(errorCode: String) {
        print("onError with code \(errorCode)")
    }
    
    func onStart() {
        print("onStart")
    }
}

struct PassBaseView : UIViewControllerRepresentable {
    typealias UIViewControllerType = PBViewController
    
    func makeUIViewController(context: Context) -> PBViewController {
        return PBViewController()
    }
    func updateUIViewController(_ uiViewController: PBViewController, context: Context) {
    }
}

In the SwiftUI view i'm trying to show the button this way:

PassBaseView()
        .frame(width: 120, height: 50, alignment: .leading)

But unfortunately the button comes out like so:

PassBase UIButton in SwiftUI

I would appreciate any suggestions on how to achieve the button to be in the center or even to embed it any way i want with remove the blank UIView space around it. Thanks!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source