Проверка шаблона шины для iOS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
689B

  1. import SwiftUI
  2. @discardableResult
  3. public func addSwiftUIViewAsChild<Type>(
  4. swiftUIView: Type,
  5. parent: UIView
  6. ) -> UIHostingController<Type> {
  7. let childVC = UIHostingController(rootView: swiftUIView)
  8. childVC.view.backgroundColor = .clear
  9. parent.addSubview(childVC.view)
  10. childVC.view.translatesAutoresizingMaskIntoConstraints = false
  11. NSLayoutConstraint.activate([
  12. childVC.view.topAnchor.constraint(equalTo: parent.topAnchor),
  13. childVC.view.bottomAnchor.constraint(equalTo: parent.bottomAnchor),
  14. childVC.view.leadingAnchor.constraint(equalTo: parent.leadingAnchor),
  15. childVC.view.trailingAnchor.constraint(equalTo: parent.trailingAnchor),
  16. ])
  17. return childVC
  18. }