d
This commit is contained in:
1 parent
acaaf68d9f
commit
30efa129a8
5 files changed
+262
No files matched your search
@@ -0,0 +1,19 @@
|
||||
import SwiftUI
|
||||
|
||||
@discardableResult
|
||||
public func addSwiftUIViewAsChild<Type>(
|
||||
swiftUIView: Type,
|
||||
parent: UIView
|
||||
) -> UIHostingController<Type> {
|
||||
let childVC = UIHostingController(rootView: swiftUIView)
|
||||
childVC.view.backgroundColor = .clear
|
||||
parent.addSubview(childVC.view)
|
||||
childVC.view.translatesAutoresizingMaskIntoConstraints = false
|
||||
NSLayoutConstraint.activate([
|
||||
childVC.view.topAnchor.constraint(equalTo: parent.topAnchor),
|
||||
childVC.view.bottomAnchor.constraint(equalTo: parent.bottomAnchor),
|
||||
childVC.view.leadingAnchor.constraint(equalTo: parent.leadingAnchor),
|
||||
childVC.view.trailingAnchor.constraint(equalTo: parent.trailingAnchor),
|
||||
])
|
||||
return childVC
|
||||
}
|
||||
Reference in new issue
Block a user